File tree Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Expand file tree Collapse file tree 2 files changed +42
-3
lines changed Original file line number Diff line number Diff line change @@ -5257,13 +5257,26 @@ getIsolationFromConformances(NominalTypeDecl *nominal) {
5257
5257
}
5258
5258
5259
5259
auto *proto = conformance->getProtocol ();
5260
- switch (auto protoIsolation = getActorIsolation (proto)) {
5260
+ auto inferredIsolation = getInferredActorIsolation (proto);
5261
+ auto protoIsolation = inferredIsolation.isolation ;
5262
+ switch (protoIsolation) {
5261
5263
case ActorIsolation::ActorInstance:
5262
5264
case ActorIsolation::Unspecified:
5263
- case ActorIsolation::Nonisolated:
5264
5265
case ActorIsolation::CallerIsolationInheriting:
5265
5266
case ActorIsolation::NonisolatedUnsafe:
5266
5267
break ;
5268
+ case ActorIsolation::Nonisolated:
5269
+ if (inferredIsolation.source .kind == IsolationSource::Kind::Explicit) {
5270
+ if (!foundIsolation) {
5271
+ // We found an explicitly 'nonisolated' protocol.
5272
+ foundIsolation = {
5273
+ protoIsolation,
5274
+ IsolationSource (proto, IsolationSource::Conformance)};
5275
+ }
5276
+ continue ;
5277
+ } else {
5278
+ break ;
5279
+ }
5267
5280
5268
5281
case ActorIsolation::Erased:
5269
5282
llvm_unreachable (" protocol cannot have erased isolation" );
Original file line number Diff line number Diff line change @@ -63,7 +63,7 @@ public struct PublicNonSendable {
63
63
}
64
64
65
65
66
- nonisolated struct NonisolatedStruct : GloballyIsolated {
66
+ nonisolated struct StructRemovesGlobalActor : GloballyIsolated {
67
67
var x : NonSendable
68
68
var y : Int = 1
69
69
@@ -104,6 +104,32 @@ struct A: Refined {
104
104
init ( x: NonSendable ) {
105
105
self . x = x // okay
106
106
}
107
+
108
+ init ( ) {
109
+ self . x = NonSendable ( )
110
+ }
111
+
112
+ func f( ) { }
113
+ }
114
+
115
+ @MainActor protocol ExplicitGlobalActor : Refined { }
116
+
117
+ struct IsolatedStruct : ExplicitGlobalActor {
118
+ // expected-note@+2 {{main actor isolation inferred from conformance to protocol 'ExplicitGlobalActor'}}
119
+ // expected-note@+1 {{calls to instance method 'g()' from outside of its actor context are implicitly asynchronous}}
120
+ func g( ) { }
121
+ }
122
+
123
+ struct NonisolatedStruct {
124
+ func callF( ) {
125
+ return A ( ) . f ( ) // okay, 'A' is non-isolated.
126
+ }
127
+
128
+ // expected-note@+1 {{add '@MainActor' to make instance method 'callG()' part of global actor 'MainActor'}}
129
+ func callG( ) {
130
+ // expected-error@+1{{call to main actor-isolated instance method 'g()' in a synchronous nonisolated context}}
131
+ return IsolatedStruct ( ) . g ( )
132
+ }
107
133
}
108
134
109
135
// MARK: - Extensions
You can’t perform that action at this time.
0 commit comments