Skip to content

Commit 355d162

Browse files
authored
Merge pull request #61994 from tshortli/improve-derived-conformance-diags-for-actors
Sema: Improve derived conformance diagnostics for actors
2 parents f00ab8a + b3403ff commit 355d162

File tree

8 files changed

+54
-14
lines changed

8 files changed

+54
-14
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,12 @@ enum class DescriptiveDeclKind : uint8_t {
159159
Enum,
160160
Struct,
161161
Class,
162+
Actor,
162163
Protocol,
163164
GenericEnum,
164165
GenericStruct,
165166
GenericClass,
167+
GenericActor,
166168
GenericType,
167169
Subscript,
168170
StaticSubscript,

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3211,8 +3211,8 @@ NOTE(missing_member_type_conformance_prevents_synthesis, none,
32113211
"of %3 to %2",
32123212
(unsigned, Type, Type, Type))
32133213
NOTE(automatic_protocol_synthesis_unsupported,none,
3214-
"automatic synthesis of '%0' is not supported for %select{classes|structs}1",
3215-
(StringRef, unsigned))
3214+
"automatic synthesis of '%0' is not supported for %1 declarations",
3215+
(StringRef, DescriptiveDeclKind))
32163216
NOTE(comparable_synthesis_raw_value_not_allowed, none,
32173217
"enum declares raw type %0, preventing synthesized conformance of %1 to %2",
32183218
(Type, Type, Type))

lib/AST/Decl.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,14 @@ DescriptiveDeclKind Decl::getDescriptiveKind() const {
180180
? DescriptiveDeclKind::GenericStruct
181181
: DescriptiveDeclKind::Struct;
182182

183-
case DeclKind::Class:
183+
case DeclKind::Class: {
184+
bool isActor = cast<ClassDecl>(this)->isActor();
184185
return cast<ClassDecl>(this)->getGenericParams()
185-
? DescriptiveDeclKind::GenericClass
186-
: DescriptiveDeclKind::Class;
186+
? (isActor ? DescriptiveDeclKind::GenericActor
187+
: DescriptiveDeclKind::GenericClass)
188+
: (isActor ? DescriptiveDeclKind::Actor
189+
: DescriptiveDeclKind::Class);
190+
}
187191

188192
case DeclKind::Var: {
189193
auto var = cast<VarDecl>(this);
@@ -317,10 +321,12 @@ StringRef Decl::getDescriptiveKindName(DescriptiveDeclKind K) {
317321
ENTRY(Enum, "enum");
318322
ENTRY(Struct, "struct");
319323
ENTRY(Class, "class");
324+
ENTRY(Actor, "actor");
320325
ENTRY(Protocol, "protocol");
321326
ENTRY(GenericEnum, "generic enum");
322327
ENTRY(GenericStruct, "generic struct");
323328
ENTRY(GenericClass, "generic class");
329+
ENTRY(GenericActor, "generic actor");
324330
ENTRY(GenericType, "generic type");
325331
ENTRY(Subscript, "subscript");
326332
ENTRY(StaticSubscript, "static subscript");

lib/Sema/DerivedConformances.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ void DerivedConformance::diagnoseIfSynthesisUnsupportedForDecl(
270270

271271
if (shouldDiagnose) {
272272
auto &ctx = nominal->getASTContext();
273-
ctx.Diags.diagnose(nominal->getLoc(),
274-
diag::automatic_protocol_synthesis_unsupported,
275-
protocol->getName().str(), isa<StructDecl>(nominal));
273+
ctx.Diags.diagnose(
274+
nominal->getLoc(), diag::automatic_protocol_synthesis_unsupported,
275+
protocol->getName().str(), nominal->getDescriptiveKind());
276276
}
277277
}
278278

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: %target-typecheck-verify-swift -disable-availability-checking
2+
// REQUIRES: concurrency
3+
4+
actor A1: Comparable {}
5+
// expected-error@-1 {{type 'A1' does not conform to protocol 'Comparable'}}
6+
// expected-error@-2 {{type 'A1' does not conform to protocol 'Equatable'}}
7+
// expected-note@-3 {{automatic synthesis of 'Comparable' is not supported for actor declarations}}
8+
// expected-note@-4 {{automatic synthesis of 'Equatable' is not supported for actor declarations}}
9+
10+
actor A2: Equatable {}
11+
// expected-error@-1 {{type 'A2' does not conform to protocol 'Equatable'}}
12+
// expected-note@-2 {{automatic synthesis of 'Equatable' is not supported for actor declarations}}
13+
14+
actor A3: Hashable {}
15+
// expected-error@-1 {{type 'A3' does not conform to protocol 'Hashable'}}
16+
// expected-error@-2 {{type 'A3' does not conform to protocol 'Equatable'}}
17+
// expected-note@-3 {{automatic synthesis of 'Hashable' is not supported for actor declarations}}
18+
// expected-note@-4 {{automatic synthesis of 'Equatable' is not supported for actor declarations}}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend-emit-module -emit-module-path %t/FakeDistributedActorSystems.swiftmodule -module-name FakeDistributedActorSystems -disable-availability-checking %S/Inputs/FakeDistributedActorSystems.swift
3+
// RUN: %target-typecheck-verify-swift -disable-availability-checking -I %t
4+
// REQUIRES: concurrency
5+
// REQUIRES: distributed
6+
7+
import Distributed
8+
import FakeDistributedActorSystems
9+
10+
typealias DefaultDistributedActorSystem = FakeActorSystem
11+
12+
distributed actor DA: Comparable {}
13+
// expected-error@-1 {{type 'DA' does not conform to protocol 'Comparable'}}
14+
// expected-note@-2 {{automatic synthesis of 'Comparable' is not supported for actor declarations}}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// RUN: %target-swift-frontend -typecheck -verify -primary-file %s
22

33
class Foo: Equatable {}
4-
// expected-error@-1 {{type 'Foo' does not conform to protocol 'Equatable'}} expected-note@-1 {{automatic synthesis of 'Equatable' is not supported for classes}}
4+
// expected-error@-1 {{type 'Foo' does not conform to protocol 'Equatable'}} expected-note@-1 {{automatic synthesis of 'Equatable' is not supported for class declarations}}
55

66
class Bar: Hashable {}
7-
// expected-error@-1 {{type 'Bar' does not conform to protocol 'Hashable'}} expected-note@-1 {{automatic synthesis of 'Hashable' is not supported for classes}}
8-
// expected-error@-2 {{type 'Bar' does not conform to protocol 'Equatable'}} expected-note@-2 {{automatic synthesis of 'Equatable' is not supported for classes}}
7+
// expected-error@-1 {{type 'Bar' does not conform to protocol 'Hashable'}} expected-note@-1 {{automatic synthesis of 'Hashable' is not supported for class declarations}}
8+
// expected-error@-2 {{type 'Bar' does not conform to protocol 'Equatable'}} expected-note@-2 {{automatic synthesis of 'Equatable' is not supported for class declarations}}

test/decl/protocol/special/comparable/comparable_unsupported.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
struct NotComparableStruct: Comparable {
66
// expected-error@-1 {{type 'NotComparableStruct' does not conform to protocol 'Comparable'}}
7-
// expected-note@-2 {{automatic synthesis of 'Comparable' is not supported for structs}}
7+
// expected-note@-2 {{automatic synthesis of 'Comparable' is not supported for struct declarations}}
88
var value = 0
99
}
1010

1111
class NotComparableClass: Comparable {
1212
// expected-error@-1 {{type 'NotComparableClass' does not conform to protocol 'Comparable'}}
13-
// expected-note@-2 {{automatic synthesis of 'Comparable' is not supported for classes}}
13+
// expected-note@-2 {{automatic synthesis of 'Comparable' is not supported for class declarations}}
1414
// expected-error@-3 {{type 'NotComparableClass' does not conform to protocol 'Equatable'}}
15-
// expected-note@-4 {{automatic synthesis of 'Equatable' is not supported for classes}}
15+
// expected-note@-4 {{automatic synthesis of 'Equatable' is not supported for class declarations}}
1616
var value = 1
1717
}
1818

0 commit comments

Comments
 (0)