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/async_let_isolation.swift
+2-5Lines changed: 2 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -5,21 +5,18 @@ actor MyActor {
5
5
letimmutable:Int=17
6
6
vartext:[String]=[]
7
7
8
-
func synchronous()->String{ text.first ??"nothing"} // expected-note 2 {{calls to instance method 'synchronous()' from outside of its actor context are implicitly asynchronous}}
// expected-note@+3 {{add '@asyncHandler' to function 'callGlobalActor()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
60
-
// expected-note@+2 {{add 'async' to function 'callGlobalActor()' to make it asynchronous}} {{23-23= async}}
61
59
// expected-note@+1 {{add '@SomeGlobalActor' to make global function 'callGlobalActor()' part of global actor 'SomeGlobalActor'}} {{1-1=@SomeGlobalActor }}
62
60
func callGlobalActor(){
63
-
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
61
+
syncGlobActorFn() // expected-error {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
64
62
}
65
63
66
64
func fromClosure(){
@@ -70,40 +68,36 @@ func fromClosure() {
70
68
x()
71
69
}()
72
70
73
-
// expected-error@+2 {{'async' in a function that does not support concurrency}}
74
71
// expected-error@+1 {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
75
72
let _ ={syncGlobActorFn()}()
76
73
}
77
74
78
75
classTaylor{
79
-
init(){ // expected-note {{add 'async' to function 'init()' to make it asynchronous}} {{9-9= async}}
80
-
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
76
+
init(){
77
+
syncGlobActorFn() // expected-error {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
81
78
82
79
// expected-error@+1 {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
83
80
_ = syncGlobActorFn
84
81
}
85
82
86
83
deinit{
87
-
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
84
+
syncGlobActorFn() // expected-error {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
88
85
89
86
// expected-error@+1 {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
90
87
_ = syncGlobActorFn
91
88
}
92
89
93
-
// expected-note@+3 2 {{add '@SomeGlobalActor' to make instance method 'method1()' part of global actor 'SomeGlobalActor'}} {{3-3=@SomeGlobalActor }}
94
-
// expected-note@+2 {{add '@asyncHandler' to function 'method1()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
95
-
// expected-note@+1 {{add 'async' to function 'method1()' to make it asynchronous}} {{17-17= async}}
90
+
// expected-note@+1 2 {{add '@SomeGlobalActor' to make instance method 'method1()' part of global actor 'SomeGlobalActor'}} {{3-3=@SomeGlobalActor }}
96
91
func method1(){
97
-
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
92
+
syncGlobActorFn() // expected-error {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
98
93
99
94
// expected-error@+1 {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
100
95
_ = syncGlobActorFn
101
96
}
102
97
103
-
// expected-note@+2 2 {{add '@SomeGlobalActor' to make instance method 'cannotBeHandler()' part of global actor 'SomeGlobalActor'}} {{3-3=@SomeGlobalActor }}
104
-
// expected-note@+1 {{add 'async' to function 'cannotBeHandler()' to make it asynchronous}}
98
+
// expected-note@+1 2 {{add '@SomeGlobalActor' to make instance method 'cannotBeHandler()' part of global actor 'SomeGlobalActor'}} {{3-3=@SomeGlobalActor }}
105
99
func cannotBeHandler()->Int{
106
-
syncGlobActorFn() // expected-error {{'async' in a function that does not support concurrency}}
100
+
syncGlobActorFn() // expected-error {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
107
101
108
102
// expected-error@+1 {{global function 'syncGlobActorFn()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
Copy file name to clipboardExpand all lines: test/Concurrency/global_actor_inference.swift
+18-28Lines changed: 18 additions & 28 deletions
Original file line number
Diff line number
Diff line change
@@ -43,24 +43,20 @@ protocol P2 {
43
43
}
44
44
45
45
classC1:P1{
46
-
func method(){} // expected-note {{calls to instance method 'method()' from outside of its actor context are implicitly asynchronous}}
46
+
func method(){} // expected-note 2 {{calls to instance method 'method()' from outside of its actor context are implicitly asynchronous}}
47
47
48
-
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
49
-
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}} {{38-38= async}}
50
48
@OtherGlobalActorfunc testMethod(){
51
-
method() // expected-error {{'async' in a function that does not support concurrency}}
49
+
method() // expected-error {{instance method 'method()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
52
50
_ = method // expected-error {{instance method 'method()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
53
51
}
54
52
}
55
53
56
54
classC2:P2{
57
-
func method1(){} // expected-note{{calls to instance method 'method1()' from outside of its actor context are implicitly asynchronous}}
55
+
func method1(){} // expected-note 2{{calls to instance method 'method1()' from outside of its actor context are implicitly asynchronous}}
58
56
func method2(){}
59
57
60
-
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
61
-
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}} {{38-38= async}}
62
58
@OtherGlobalActorfunc testMethod(){
63
-
method1() // expected-error{{'async' in a function that does not support concurrency}}
59
+
method1() // expected-error{{instance method 'method1()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
64
60
_ = method1 // expected-error{{instance method 'method1()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
65
61
method2() // okay
66
62
}
@@ -70,49 +66,47 @@ class C2: P2 {
70
66
// Global actor inference for classes and extensions
func method1(){} // expected-note {{calls to instance method 'method1()' from outside of its actor context are implicitly asynchronous}}
69
+
func method1(){} // expected-note 2{{calls to instance method 'method1()' from outside of its actor context are implicitly asynchronous}}
74
70
}
75
71
76
72
extensionC3{
77
-
func method2(){} // expected-note {{calls to instance method 'method2()' from outside of its actor context are implicitly asynchronous}}
73
+
func method2(){} // expected-note 2{{calls to instance method 'method2()' from outside of its actor context are implicitly asynchronous}}
78
74
}
79
75
80
76
classC4:C3{
81
-
func method3(){} // expected-note {{calls to instance method 'method3()' from outside of its actor context are implicitly asynchronous}}
77
+
func method3(){} // expected-note 2{{calls to instance method 'method3()' from outside of its actor context are implicitly asynchronous}}
82
78
}
83
79
84
80
extensionC4{
85
-
func method4(){} // expected-note {{calls to instance method 'method4()' from outside of its actor context are implicitly asynchronous}}
81
+
func method4(){} // expected-note 2{{calls to instance method 'method4()' from outside of its actor context are implicitly asynchronous}}
86
82
}
87
83
88
84
classC5{
89
85
func method1(){}
90
86
}
91
87
92
88
@SomeGlobalActorextensionC5{
93
-
func method2(){} // expected-note {{calls to instance method 'method2()' from outside of its actor context are implicitly asynchronous}}
89
+
func method2(){} // expected-note 2{{calls to instance method 'method2()' from outside of its actor context are implicitly asynchronous}}
94
90
}
95
91
96
-
// expected-note@+2 5 {{add '@asyncHandler' to function 'testGlobalActorInference(c3:c4:c5:)' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
97
-
// expected-note@+1 5 {{add 'async' to function 'testGlobalActorInference(c3:c4:c5:)' to make it asynchronous}} {{72-72= async}}
c3.method1() // expected-error{{'async' in a function that does not support concurrency}}
101
-
c3.method2() // expected-error{{'async' in a function that does not support concurrency}}
94
+
c3.method1() // expected-error{{instance method 'method1()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
95
+
c3.method2() // expected-error{{instance method 'method2()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
102
96
103
97
_ = c3.method1 // expected-error{{instance method 'method1()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
104
98
_ = c3.method2 // expected-error{{instance method 'method2()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
105
99
106
100
// Propagation via subclassing
107
-
c4.method3() // expected-error{{'async' in a function that does not support concurrency}}
108
-
c4.method4() // expected-error{{'async' in a function that does not support concurrency}}
101
+
c4.method3() // expected-error{{instance method 'method3()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
102
+
c4.method4() // expected-error{{instance method 'method4()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
109
103
110
104
_ = c4.method3 // expected-error{{instance method 'method3()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
111
105
_ = c4.method4 // expected-error{{instance method 'method4()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
112
106
113
107
// Propagation in an extension.
114
108
c5.method1() // OK: no propagation
115
-
c5.method2() // expected-error{{'async' in a function that does not support concurrency}}
109
+
c5.method2() // expected-error{{instance method 'method2()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
116
110
117
111
_ = c5.method1 // OK
118
112
_ = c5.method2 // expected-error{{instance method 'method2()' isolated to global actor 'SomeGlobalActor' can not be referenced from different global actor 'OtherGlobalActor'}}
@@ -150,15 +144,13 @@ actor GenericSuper<T> {
150
144
}
151
145
152
146
actorGenericSub<T>:GenericSuper<[T]>{
153
-
overridefunc method(){} // expected-note{{calls to instance method 'method()' from outside of its actor context are implicitly asynchronous}}
147
+
overridefunc method(){} // expected-note 2{{calls to instance method 'method()' from outside of its actor context are implicitly asynchronous}}
154
148
155
149
@GenericGlobalActor<T>overridefunc method2(){} // expected-error{{global actor 'GenericGlobalActor<T>'-isolated instance method 'method2()' has different actor isolation from global actor 'GenericGlobalActor<[T]>'-isolated overridden declaration}}
156
150
@actorIndependentoverridefunc method3(){} // expected-error{{actor-independent instance method 'method3()' has different actor isolation from global actor 'GenericGlobalActor<[T]>'-isolated overridden declaration}}
157
151
158
-
// expected-note@+2 {{add '@asyncHandler' to function 'testMethod()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
159
-
// expected-note@+1 {{add 'async' to function 'testMethod()' to make it asynchronous}} {{38-38= async}}
160
152
@OtherGlobalActorfunc testMethod(){
161
-
method() // expected-error{{'async' in a function that does not support concurrency}}
153
+
method() // expected-error{{instance method 'method()' isolated to global actor 'GenericGlobalActor<[T]>' can not be referenced from different global actor 'OtherGlobalActor'}}
162
154
_ = method // expected-error{{instance method 'method()' isolated to global actor 'GenericGlobalActor<[T]>' can not be referenced from different global actor 'OtherGlobalActor'}}
163
155
}
164
156
}
@@ -231,9 +223,7 @@ func bar() async {
231
223
foo() // expected-error{{call is 'async' but is not marked with 'await'}}
232
224
}
233
225
234
-
// expected-note@+3 {{add '@SomeGlobalActor' to make global function 'barSync()' part of global actor 'SomeGlobalActor'}} {{1-1=@SomeGlobalActor }}
235
-
// expected-note@+2 {{add '@asyncHandler' to function 'barSync()' to create an implicit asynchronous context}} {{1-1=@asyncHandler }}
236
-
// expected-note@+1 {{add 'async' to function 'barSync()' to make it asynchronous}} {{15-15= async}}
226
+
// expected-note@+1 {{add '@SomeGlobalActor' to make global function 'barSync()' part of global actor 'SomeGlobalActor'}} {{1-1=@SomeGlobalActor }}
237
227
func barSync(){
238
-
foo() // expected-error {{'async' in a function that does not support concurrency}}
228
+
foo() // expected-error {{global function 'foo()' isolated to global actor 'SomeGlobalActor' can not be referenced from this context}}
0 commit comments