File tree 3 files changed +40
-5
lines changed
3 files changed +40
-5
lines changed Original file line number Diff line number Diff line change @@ -550,6 +550,12 @@ deriveHashable_hashInto(
550
550
hashDecl->copyFormalAccessFrom (derived.Nominal ,
551
551
/* sourceIsParentContext=*/ true );
552
552
553
+ // The derived hash(into:) for an actor must be non-isolated.
554
+ if (derived.Nominal ->isActor () ||
555
+ getActorIsolation (derived.Nominal ) == ActorIsolation::GlobalActor) {
556
+ hashDecl->getAttrs ().add (new (C) NonisolatedAttr (/* IsImplicit*/ true ));
557
+ }
558
+
553
559
derived.addMembersToConformanceContext ({hashDecl});
554
560
555
561
return hashDecl;
@@ -904,10 +910,9 @@ static ValueDecl *deriveHashable_hashValue(DerivedConformance &derived) {
904
910
hashValueDecl->copyFormalAccessFrom (derived.Nominal ,
905
911
/* sourceIsParentContext*/ true );
906
912
907
- if (derived.Nominal ->isDistributedActor ()) {
908
- // While distributed actors implement hash(into:) explicitly, the hashValue
909
- // is still synthesized as usual. We must make it nonisolated in order
910
- // for the hashValue to be able to witness the protocol requirement.
913
+ // The derived hashValue of an actor must be nonisolated.
914
+ if (derived.Nominal ->isActor () ||
915
+ getActorIsolation (derived.Nominal ) == ActorIsolation::GlobalActor) {
911
916
hashValueDecl->getAttrs ().add (new (C) NonisolatedAttr (/* IsImplicit*/ true ));
912
917
}
913
918
Original file line number Diff line number Diff line change
1
+ // RUN: %target-typecheck-verify-swift
2
+ // REQUIRES: concurrency
3
+
4
+ @available ( SwiftStdlib 5 . 5 , * )
5
+ actor A1 : Hashable {
6
+ nonisolated func hash( into hasher: inout Hasher ) { }
7
+ static func == ( lhs: A1 , rhs: A1 ) -> Bool { true }
8
+ }
9
+
10
+ @available ( SwiftStdlib 5 . 5 , * )
11
+ actor A2 : Hashable {
12
+ nonisolated var hashValue : Int { 0 } // expected-warning{{'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'A2' to 'Hashable' by implementing 'hash(into:)' instead}}
13
+ static func == ( lhs: A2 , rhs: A2 ) -> Bool { true }
14
+ }
15
+
16
+
17
+ @available ( SwiftStdlib 5 . 5 , * )
18
+ @MainActor
19
+ class C1 : Hashable {
20
+ nonisolated func hash( into hasher: inout Hasher ) { }
21
+ nonisolated static func == ( lhs: C1 , rhs: C1 ) -> Bool { true }
22
+ }
23
+
24
+ @available ( SwiftStdlib 5 . 5 , * )
25
+ @MainActor
26
+ class C2 : Hashable {
27
+ nonisolated var hashValue : Int { 0 } // expected-warning{{'Hashable.hashValue' is deprecated as a protocol requirement; conform type 'C2' to 'Hashable' by implementing 'hash(into:)' instead}}
28
+ nonisolated static func == ( lhs: C2 , rhs: C2 ) -> Bool { true }
29
+ }
30
+
Original file line number Diff line number Diff line change 1
1
// RUN: %target-typecheck-verify-swift -enable-experimental-concurrency
2
2
// REQUIRES: concurrency
3
3
4
- // Synthesis of for actores .
4
+ // Synthesis of conformances for actors .
5
5
6
6
@available ( SwiftStdlib 5 . 5 , * )
7
7
actor A1 {
You can’t perform that action at this time.
0 commit comments