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
[SE-0470] Prohibit inference of isolated conformances with nonisolated witnesses
If all of the witnesses to a conformance are nonisolated, then infer that
conformance as nonisolated rather than global-actor-isolated. This is
only relevant when InferIsolatedConformances is enabled, and prevents
that inference to help maintain source compatibility.
let _:anyP=CExplicitMainActor() // expected-error{{main actor-isolated conformance of 'CExplicitMainActor' to 'P' cannot be used in nonisolated context}}
50
-
let _:anyP=CImplicitMainActor() // expected-error{{main actor-isolated conformance of 'CImplicitMainActor' to 'P' cannot be used in nonisolated context}}
49
+
let _:anyP=CExplicitMainActor() // okay
50
+
let _:anyP=CImplicitMainActor() // okay
51
51
52
52
let _:anyP=CNonIsolated()
53
53
let _:anyP=CImplicitMainActorNonisolatedConformance()
Copy file name to clipboardExpand all lines: test/Concurrency/isolated_conformance_inference.swift
+7Lines changed: 7 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -32,6 +32,11 @@ extension CExplicit: Q {
32
32
func g(){}
33
33
}
34
34
35
+
@SomeGlobalActor
36
+
classCViaNonisolatedWitness:P{
37
+
nonisolatedfunc f(){} // okay! conformance above is nonisolated via this witness
38
+
}
39
+
35
40
// expected-error@+3{{conformance of 'CNonIsolated' to protocol 'P' crosses into global actor 'SomeGlobalActor'-isolated code and can cause data races}}
36
41
// expected-note@+2{{turn data races into runtime errors with '@preconcurrency'}}
37
42
// expected-note@+1{{isolate this conformance to the global actor 'SomeGlobalActor' with '@SomeGlobalActor'}}{{33-33=@SomeGlobalActor }}
0 commit comments