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
// This note is tailored for the 'mutating' access, i.e. when
1845
+
// attempting to mutate a property, they should instead make an actor method to perform the mutation. Reading properties does not have the same restriction.
1846
+
return;
1847
+
}
1848
+
1849
+
if (!refCxt->isAsyncContext()) {
1850
+
// don't suggest creating method when in sync context, as we won't be able
1851
+
// to invoke it anyway so this would not be helpful to suggest
dollarsInBananaStand = money // expected-error{{global actor 'BananaActor'-isolated var 'dollarsInBananaStand' can not be mutated from global actor 'OrangeActor'}}
284
+
// expected-error@+2{{global actor 'BananaActor'-isolated var 'dollarsInBananaStand' can not be mutated from global actor 'OrangeActor'}}
285
+
// expected-note@+1{{consider declaring an isolated method on 'BananaActor' to perform the mutation}}
286
+
dollarsInBananaStand = money
283
287
284
288
// FIXME: these two errors seem a bit redundant.
285
289
// expected-error@+2 {{actor-isolated var 'dollarsInBananaStand' cannot be passed 'inout' to implicitly 'async' function call}}
act.mutable +=1 // expected-error {{actor-isolated property 'mutable' can not be mutated from a nonisolated context}}
101
+
// expected-note@-1{{consider declaring an isolated method on 'MyActor' to perform the mutation}}
101
102
102
103
act.superState +=1 // expected-error {{actor-isolated property 'superState' can not be mutated from a nonisolated context}}
104
+
// expected-note@-1{{consider declaring an isolated method on 'MySuperActor' to perform the mutation}}
103
105
104
106
act.text[0].append("hello") // expected-error{{actor-isolated property 'text' can not be mutated from a nonisolated context}}
107
+
// expected-note@-1{{consider declaring an isolated method on 'MyActor' to perform the mutation}}
105
108
106
109
// this is not the same as the above, because Array is a value type
107
110
vararr=await act.text
108
111
arr[0].append("hello")
109
112
110
113
act.text.append("no") // expected-error{{actor-isolated property 'text' can not be mutated from a nonisolated context}}
114
+
// expected-note@-1{{consider declaring an isolated method on 'MyActor' to perform the mutation}}
111
115
112
116
act.text[0]+="hello" // expected-error{{actor-isolated property 'text' can not be mutated from a nonisolated context}}
117
+
// expected-note@-1{{consider declaring an isolated method on 'MyActor' to perform the mutation}}
113
118
114
119
_ = act.point // expected-warning{{non-sendable type 'Point' of property 'point' cannot exit actor-isolated context}}
115
120
// expected-warning@-1 {{expression is 'async' but is not marked with 'await'}}
@@ -269,9 +274,11 @@ extension MyActor {
269
274
// expected-note@-1{{property access is 'async'}}
270
275
_ =await otherActor.mutable
271
276
otherActor.mutable =0 // expected-error{{actor-isolated property 'mutable' can not be mutated on a nonisolated actor instance}}
277
+
// expected-note@-1{{consider declaring an isolated method on 'MyActor' to perform the mutation}}
272
278
acceptInout(&otherActor.mutable) // expected-error{{actor-isolated property 'mutable' can not be used 'inout' on a nonisolated actor instance}}
273
-
// expected-error@+2{{actor-isolated property 'mutable' can not be mutated on a nonisolated actor instance}}
274
-
// expected-warning@+1{{no 'async' operations occur within 'await' expression}}
279
+
// expected-error@+3{{actor-isolated property 'mutable' can not be mutated on a nonisolated actor instance}}
280
+
// expected-warning@+2{{no 'async' operations occur within 'await' expression}}
281
+
// expected-note@+1{{consider declaring an isolated method on 'MyActor' to perform the mutation}}
275
282
await otherActor.mutable =0
276
283
277
284
_ = otherActor.synchronous()
@@ -443,8 +450,10 @@ actor Crystal {
443
450
_ =await globActorVar + globActorProp
444
451
445
452
globActorProp =20 // expected-error {{global actor 'SomeGlobalActor'-isolated property 'globActorProp' can not be mutated on a different actor instance}}
453
+
// expected-note@-1{{consider declaring an isolated method on 'SomeGlobalActor' to perform the mutation}}
446
454
447
455
globActorVar =30 // expected-error {{global actor 'SomeGlobalActor'-isolated property 'globActorVar' can not be mutated on a different actor instance}}
456
+
// expected-note@-1{{consider declaring an isolated method on 'SomeGlobalActor' to perform the mutation}}
448
457
449
458
// expected-error@+2 {{global actor 'SomeGlobalActor'-isolated property 'globActorVar' can not be used 'inout' on a different actor instance}}
450
459
// expected-error@+1 {{actor-isolated property 'globActorVar' cannot be passed 'inout' to implicitly 'async' function call}}
// expected-note@+1 3 {{mutation of this property is only permitted within the actor}}
876
+
// expected-note@+1 4 {{mutation of this property is only permitted within the actor}}
868
877
varmutableState:Int=17
869
878
varotherMutableState:Int
870
879
// expected-note@+1 {{mutation of this property is only permitted within the actor}}
@@ -896,6 +905,14 @@ actor SomeActorWithInits {
896
905
}
897
906
local()
898
907
908
+
func localAsync()async{
909
+
isolated() // expected-warning{{actor-isolated instance method 'isolated()' can not be referenced from a nonisolated context; this is an error in the Swift 6 language mode}}
910
+
mutableState +=1 // expected-warning{{actor-isolated property 'mutableState' can not be mutated from a nonisolated context; this is an error in the Swift 6 language mode}}
911
+
// expected-note@-1{{consider declaring an isolated method on 'SomeActorWithInits' to perform the mutation}}
912
+
nonisolated()
913
+
}
914
+
Task{awaitlocalAsync()}
915
+
899
916
let _ ={
900
917
defer{
901
918
isolated() // expected-warning{{actor-isolated instance method 'isolated()' can not be referenced from a nonisolated context; this is an error in the Swift 6 language mode}}
@@ -990,8 +1007,7 @@ actor SomeActorWithInits {
990
1007
}()
991
1008
}
992
1009
993
-
994
-
func isolated(){} // expected-note 9 {{calls to instance method 'isolated()' from outside of its actor context are implicitly asynchronous}}
1010
+
func isolated(){} // expected-note 10 {{calls to instance method 'isolated()' from outside of its actor context are implicitly asynchronous}}
995
1011
nonisolatedfunc nonisolated(){}
996
1012
}
997
1013
@@ -1346,6 +1362,7 @@ actor Butterfly {
1346
1362
nonisolatedinit(cookies:Void)async{
1347
1363
self.init()
1348
1364
self.flapsPerSec +=1 // expected-error {{actor-isolated property 'flapsPerSec' can not be mutated from a nonisolated context}}
1365
+
// expected-note@-1 {{consider declaring an isolated method on 'Butterfly' to perform the mutation}}
0 commit comments