Skip to content

Commit b3403ff

Browse files
committed
Sema: Improve derived conformance diagnostics for actors.
Previously, actor declarations were identified by the diagnostics as classes.
1 parent 114ee28 commit b3403ff

File tree

6 files changed

+43
-11
lines changed

6 files changed

+43
-11
lines changed

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/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)