You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Isolated conformances] Allow conformance isolation to differ from the type's
With the move to explicitly specifying the global actor for an isolated
conformance, we can now have conformances whose isolation differs from
that of the type, including having actors with global-actor-isolated
conformances. Introduce this generalization to match the proposal, and
update/add tests accordingly.
// Isolated conformances need a global-actor-constrained type.
25
-
classCNonIsolated:@MainActorP{ // expected-error{{isolated conformance is only permitted on global-actor-isolated types}}
25
+
classCNonIsolated:@MainActorP{
26
26
func f(){}
27
27
}
28
28
29
-
extensionSomeActor:@MainActorP{ // expected-error{{isolated conformance is only permitted on global-actor-isolated types}}
30
-
nonisolatedfunc f(){}
29
+
extensionSomeActor:@MainActorP{
30
+
@MainActorfunc f(){}
31
31
}
32
32
33
33
@globalActor
34
34
structSomeGlobalActor{
35
35
staticletshared=SomeActor()
36
36
}
37
37
38
-
// Isolation of the conformance needs to match that of the enclosing type.
38
+
// Isolation of the conformance can be different from that of the enclosing
39
+
// type, so long as the witnesses match up.
39
40
@MainActor
40
41
classCMismatchedIsolation:@SomeGlobalActorP{
41
-
@SomeGlobalActorfunc f(){} // expected-error{{global actor 'SomeGlobalActor'-isolated instance method 'f()' cannot be used to satisfy nonisolated requirement from protocol 'P'}}
42
+
@SomeGlobalActorfunc f(){}
42
43
}
43
44
44
45
@MainActor
@@ -52,7 +53,7 @@ protocol Q {
52
53
associatedtypeA:P
53
54
}
54
55
55
-
// expected-error@+2{{conformance of 'SMissingIsolation' to 'Q' depends on main actor-isolated conformance of 'C' to 'P'; mark it as 'isolated'}}{{27-27=isolated }}
56
+
// expected-error@+2{{conformance of 'SMissingIsolation' to 'Q' depends on main actor-isolated conformance of 'C' to 'P'; mark it as '@MainActor'}}{{27-27=@MainActor }}
56
57
@MainActor
57
58
structSMissingIsolation:Q{
58
59
typealiasA=C
@@ -62,7 +63,7 @@ struct PWrapper<T: P>: P {
62
63
func f(){}
63
64
}
64
65
65
-
// expected-error@+2{{conformance of 'SMissingIsolationViaWrapper' to 'Q' depends on main actor-isolated conformance of 'C' to 'P'; mark it as 'isolated'}}
66
+
// expected-error@+2{{conformance of 'SMissingIsolationViaWrapper' to 'Q' depends on main actor-isolated conformance of 'C' to 'P'; mark it as '@MainActor'}}
acceptSendableP(c) // expected-error{{isolated conformance of 'C' to 'P' cannot be used to satisfy conformance requirement for a `Sendable` type parameter}}
121
+
acceptSendableP(c) // expected-error{{main actor-isolated conformance of 'C' to 'P' cannot be used to satisfy conformance requirement for a `Sendable` type parameter}}
121
122
acceptSendableMetaP(c) // expected-error{{isolated conformance of 'C' to 'P' cannot be used to satisfy conformance requirement for a `Sendable` type parameter}}
acceptSendableMetaP(a) // expected-error{{main actor-isolated conformance of 'SomeActor' to 'P' cannot be used to satisfy conformance requirement for a `Sendable` type parameter}}
acceptSendableMetaP(c) // expected-error{{global actor 'SomeGlobalActor'-isolated conformance of 'CMismatchedIsolation' to 'P' cannot be used to satisfy conformance requirement for a `Sendable` type parameter}}
135
+
}
136
+
124
137
func testIsolationConformancesFromOutside(c:C){
125
-
acceptP(c) // expected-error{{main actor-isolated isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
126
-
let _:anyP= c // expected-error{{main actor-isolated isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
127
-
let _ =PWrapper<C>() // expected-error{{main actor-isolated isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
138
+
acceptP(c) // expected-error{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
139
+
let _:anyP= c // expected-error{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
140
+
let _ =PWrapper<C>() // expected-error{{main actor-isolated conformance of 'C' to 'P' cannot be used in nonisolated context}}
0 commit comments