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
Copy file name to clipboardExpand all lines: test/Concurrency/actor_isolation.swift
+11Lines changed: 11 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -655,4 +655,15 @@ class SomeClassWithInits {
655
655
}
656
656
657
657
func isolated(){}
658
+
659
+
func hasDetached(){
660
+
Task.runDetached{
661
+
// okay
662
+
awaitself.isolated() // expected-warning{{cannot use parameter 'self' with a non-concurrent-value type 'SomeClassWithInits' from concurrently-executed code}}
663
+
self.isolated() // expected-warning{{cannot use parameter 'self' with a non-concurrent-value type 'SomeClassWithInits' from concurrently-executed code}}
664
+
// expected-error@-1{{call is 'async' but is not marked with 'await'}}
665
+
666
+
print(awaitself.mutableState) // expected-warning{{cannot use parameter 'self' with a non-concurrent-value type 'SomeClassWithInits' from concurrently-executed code}}
@MainActor(unsafe)func globalMain(){} // expected-note {{calls to global function 'globalMain()' from outside of its actor context are implicitly asynchronous}}
9
+
10
+
@SomeGlobalActor(unsafe)func globalSome(){} // expected-note 2{{calls to global function 'globalSome()' from outside of its actor context are implicitly asynchronous}}
@SomeGlobalActorfunc onMainActor(){} // expected-error{{instance method 'onMainActor()' isolated to global actor 'SomeGlobalActor' can not satisfy corresponding requirement from protocol 'P1' isolated to global actor 'MainActor'}}
@MainActor(unsafe)func method(){} // expected-note{{overridden declaration is here}}
40
+
}
41
+
42
+
classC2:C1{
43
+
overridefunc method(){ // expected-note{{overridden declaration is here}}
44
+
globalSome() // okay
45
+
}
46
+
}
47
+
48
+
classC3:C1{
49
+
@actorIndependentoverridefunc method(){
50
+
globalSome() // expected-error{{global function 'globalSome()' isolated to global actor 'SomeGlobalActor' can not be referenced from an '@actorIndependent' synchronous context}}
51
+
}
52
+
}
53
+
54
+
classC4:C1{
55
+
@MainActoroverridefunc method(){
56
+
globalSome() // expected-error{{global function 'globalSome()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'MainActor'}}
57
+
}
58
+
}
59
+
60
+
classC5:C1{
61
+
@SomeGlobalActoroverridefunc method(){ // expected-error{{global actor 'SomeGlobalActor'-isolated instance method 'method()' has different actor isolation from global actor 'MainActor'-isolated overridden declaration}}
62
+
}
63
+
}
64
+
65
+
classC6:C2{
66
+
// We didn't infer any actor isolation for C2.method().
67
+
@SomeGlobalActoroverridefunc method(){ // expected-error{{global actor 'SomeGlobalActor'-isolated instance method 'method()' has different actor isolation from non-actor-isolated overridden declaration}}
68
+
}
69
+
}
70
+
71
+
classC7:C2{
72
+
// We didn't infer any actor isolation for C2.method(), but it's okay to be
73
+
// explicitly unsafe.
74
+
@SomeGlobalActor(unsafe)overridefunc method(){
75
+
globalMain() // expected-error{{global function 'globalMain()' isolated to global actor 'MainActor' can not be referenced from different global actor 'SomeGlobalActor'}}
0 commit comments