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
func synchronous()->String{ text.first ??"nothing"} // expected-note 21{{calls to instance method 'synchronous()' from outside of its actor context are implicitly asynchronous}}
38
+
func synchronous()->String{ text.first ??"nothing"} // expected-note 20{{calls to instance method 'synchronous()' from outside of its actor context are implicitly asynchronous}}
39
39
func asynchronous()async->String{synchronous()}
40
40
}
41
41
@@ -45,7 +45,6 @@ extension MyActor {
45
45
set{}
46
46
}
47
47
48
-
// expected-note@+1 {{add 'async' to function 'actorIndependentFunc(otherActor:)' to make it asynchronous}} {{67-67= async}}
_ =text[0] // expected-error{{actor-isolated property 'text' can not be referenced from an '@actorIndependent' context}}
@@ -65,8 +64,11 @@ extension MyActor {
65
64
_ = otherActor.actorIndependentVar
66
65
otherActor.actorIndependentVar =17
67
66
67
+
// async promotion
68
+
_ =synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from an '@actorIndependent' context}}
69
+
68
70
// Global actors
69
-
syncGlobalActorFunc() /// expected-error{{'async' in a function that does not support concurrency}}
71
+
syncGlobalActorFunc() /// expected-error{{global function 'syncGlobalActorFunc()' isolated to global actor 'SomeGlobalActor' can not be referenced from an '@actorIndependent' context}}
70
72
_ = syncGlobalActorFunc // expected-error{{global function 'syncGlobalActorFunc()' isolated to global actor 'SomeGlobalActor' can not be referenced from an '@actorIndependent' context}}
@SomeGlobalActorfunc syncGlobalActorFunc(){syncGlobalActorFunc()} // expected-note{{calls to global function 'syncGlobalActorFunc()' from outside of its actor context are implicitly asynchronous}}
237
+
@SomeGlobalActorfunc syncGlobalActorFunc(){syncGlobalActorFunc()} // expected-note 2{{calls to global function 'syncGlobalActorFunc()' from outside of its actor context are implicitly asynchronous}}
_ =synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from context of global actor 'SomeGlobalActor'}}
265
+
_ =synchronous() // expected-error{{call is 'async' but is not marked with 'await'}}
266
+
_ =awaitsynchronous()
264
267
_ =text[0] // expected-error{{actor-isolated property 'text' can not be referenced from context of global actor 'SomeGlobalActor'}}
265
268
266
269
// Accesses on 'self' are only okay for immutable and asynchronous, because
267
270
// we are outside of the actor instance.
268
271
_ =self.immutable
269
-
_ =self.synchronous() // expected-error{{actor-isolated instance method 'synchronous()' can not be referenced from context of global actor 'SomeGlobalActor'}}
272
+
_ =self.synchronous() // expected-error{{call is 'async' but is not marked with 'await'}}
273
+
_ =awaitself.synchronous()
274
+
270
275
_ =awaitself.asynchronous()
271
276
_ =self.text[0] // expected-error{{actor-isolated property 'text' can not be referenced from context of global actor 'SomeGlobalActor'}}
272
277
_ =self[0] // expected-error{{actor-isolated subscript 'subscript(_:)' can not be referenced from context of global actor 'SomeGlobalActor'}}
273
278
274
279
// Accesses on 'super' are not okay; we're outside of the actor.
275
280
_ = super.superState // expected-error{{actor-isolated property 'superState' can not be referenced from context of global actor 'SomeGlobalActor'}}
276
-
super.superMethod() // expected-error{{actor-isolated instance method 'superMethod()' can not be referenced from context of global actor 'SomeGlobalActor'}}
281
+
super.superMethod() // expected-error{{call is 'async' but is not marked with 'await'}}
282
+
await super.superMethod()
277
283
await super.superAsyncMethod()
278
284
_ = super[0] // expected-error{{actor-isolated subscript 'subscript(_:)' can not be referenced from context of global actor 'SomeGlobalActor'}}
279
285
@@ -288,16 +294,14 @@ extension MyActor {
288
294
}
289
295
290
296
structGenericStruct<T>{
291
-
@GenericGlobalActor<T>func f(){} // expected-note{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
297
+
@GenericGlobalActor<T>func f(){} // expected-note 2{{calls to instance method 'f()' from outside of its actor context are implicitly asynchronous}}
292
298
293
299
@GenericGlobalActor<T>func g(){
294
300
f() // okay
295
301
}
296
302
297
-
// expected-note@+2 {{add '@asyncHandler' to function 'h()' to create an implicit asynchronous context}} {{3-3=@asyncHandler }}
298
-
// expected-note@+1 {{add 'async' to function 'h()' to make it asynchronous}} {{39-39= async}}
299
303
@GenericGlobalActor<String>func h(){
300
-
f() // expected-error{{'async' in a function that does not support concurrency}}
304
+
f() // expected-error{{instance method 'f()' isolated to global actor 'GenericGlobalActor<T>' can not be referenced from different global actor 'GenericGlobalActor<String>'}}
301
305
_ = f // expected-error{{instance method 'f()' isolated to global actor 'GenericGlobalActor<T>' can not be referenced from different global actor 'GenericGlobalActor<String>'}}
302
306
}
303
307
}
@@ -472,9 +476,7 @@ class SomeClassInActor {
472
476
473
477
extensionSomeClassInActor.ID{
474
478
func f(_ object:SomeClassInActor){ // expected-note{{add '@MainActor' to make instance method 'f' part of global actor 'MainActor'}}
475
-
// expected-note@-1{{add 'async' to function 'f' to make it asynchronous}}
476
-
// expected-note@-2{{add '@asyncHandler' to function 'f' to create an implicit asynchronous context}}
477
-
object.inActor() // expected-error{{'async' in a function that does not support concurrency}}
479
+
object.inActor() // expected-error{{instance method 'inActor()' isolated to global actor 'MainActor' can not be referenced from this context}}
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}}
0 commit comments