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
[Actor inference] Infer global actors on all value members of a type.
Rather than restricting inference of global actors to instance members,
as we do for actor types, infer global actors for all value members,
which also includes static variables and methods, initializers, and
destructors.
func isolated(){} // expected-note{{calls to instance method 'isolated()' from outside of its actor context are implicitly asynchronous}}
663
+
func isolated(){}
664
+
665
+
staticfunc staticIsolated(){ // expected-note{{calls to static method 'staticIsolated()' from outside of its actor context are implicitly asynchronous}}
666
+
_ =SomeClassWithInits.shared
667
+
}
658
668
659
669
func hasDetached(){
660
670
Task.runDetached{
@@ -668,8 +678,10 @@ class SomeClassWithInits {
668
678
}
669
679
}
670
680
671
-
func outsideSomeClassWithInits(){
672
-
_ =SomeClassWithInits() // okay, initializer is not isolated
681
+
func outsideSomeClassWithInits(){ // expected-note 3 {{add '@MainActor' to make global function 'outsideSomeClassWithInits()' part of global actor 'MainActor'}}
682
+
_ =SomeClassWithInits() // expected-error{{initializer 'init()' isolated to global actor 'MainActor' can not be referenced from this synchronous context}}
683
+
_ =SomeClassWithInits.shared // expected-error{{static property 'shared' isolated to global actor 'MainActor' can not be referenced from this synchronous context}}
684
+
SomeClassWithInits.staticIsolated() // expected-error{{static method 'staticIsolated()' isolated to global actor 'MainActor' can not be referenced from this synchronous context}}
0 commit comments