Skip to content

Commit fcd93a5

Browse files
committed
[Distributed] Improve error messages for protocol conformances
1 parent 71cdfff commit fcd93a5

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

include/swift/AST/Decl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ enum class DescriptiveDeclKind : uint8_t {
169169
Method,
170170
StaticMethod,
171171
ClassMethod,
172+
DistributedMethod,
172173
Getter,
173174
Setter,
174175
Addressor,

lib/AST/Decl.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,11 @@ DescriptiveDeclKind Decl::getDescriptiveKind() const {
258258
// We have a method.
259259
switch (func->getCorrectStaticSpelling()) {
260260
case StaticSpellingKind::None:
261-
return DescriptiveDeclKind::Method;
261+
if (func->isDistributed()) {
262+
return DescriptiveDeclKind::DistributedMethod;
263+
} else {
264+
return DescriptiveDeclKind::Method;
265+
}
262266
case StaticSpellingKind::KeywordStatic:
263267
return DescriptiveDeclKind::StaticMethod;
264268
case StaticSpellingKind::KeywordClass:
@@ -320,6 +324,7 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
320324
ENTRY(Method, "instance method");
321325
ENTRY(StaticMethod, "static method");
322326
ENTRY(ClassMethod, "class method");
327+
ENTRY(DistributedMethod, "distributed method");
323328
ENTRY(Getter, "getter");
324329
ENTRY(Setter, "setter");
325330
ENTRY(WillSet, "willSet observer");

test/Distributed/distributed_actor_protocol_isolation.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ typealias DefaultActorTransport = AnyActorTransport
1212

1313
protocol LocalProto {
1414
func local()
15+
// expected-note@-1{{mark the protocol requirement 'local()' 'async throws' in order witness it with 'distributed' function declared in distributed actor 'DAD'}}
1516
func localAsync() async
17+
// expected-note@-1{{mark the protocol requirement 'localAsync()' 'throws' in order witness it with 'distributed' function declared in distributed actor 'DAD'}}
1618
func localThrows() throws
19+
// expected-note@-1{{mark the protocol requirement 'localThrows()' 'async' in order witness it with 'distributed' function declared in distributed actor 'DAD'}}
1720
func localAsyncThrows() async throws
1821
}
1922

@@ -56,6 +59,21 @@ distributed actor DAL: LocalProto {
5659
// expected-error@-1{{actor-isolated instance method 'localAsyncThrows()' cannot be used to satisfy a protocol requirement}}
5760
}
5861

62+
distributed actor DAD: LocalProto {
63+
distributed func local() {}
64+
// expected-error@-1{{distributed actor-isolated distributed method 'local()' cannot be used to satisfy a protocol requirement}}
65+
// expected-note@-2{{add 'nonisolated' to 'local()' to make this distributed method not isolated to the actor}}
66+
67+
distributed func localAsync() async {}
68+
// expected-error@-1{{distributed actor-isolated distributed method 'localAsync()' cannot be used to satisfy a protocol requirement}}
69+
70+
distributed func localThrows() throws {}
71+
// expected-error@-1{{distributed actor-isolated distributed method 'localThrows()' cannot be used to satisfy a protocol requirement}}
72+
// expected-note@-2{{add 'nonisolated' to 'localThrows()' to make this distributed method not isolated to the actor}}
73+
74+
distributed func localAsyncThrows() async throws {} // ok!
75+
}
76+
5977
// ==== ------------------------------------------------------------------------
6078

6179
distributed actor DA2: DistProtoDistributedActor {

0 commit comments

Comments
 (0)