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 @@ -5184,13 +5184,26 @@ getIsolationFromConformances(NominalTypeDecl *nominal) {
5184
5184
}
5185
5185
5186
5186
auto *proto = conformance->getProtocol ();
5187
- switch (auto protoIsolation = getActorIsolation (proto)) {
5187
+ auto inferredIsolation = getInferredActorIsolation (proto);
5188
+ auto protoIsolation = inferredIsolation.isolation ;
5189
+ switch (protoIsolation) {
5188
5190
case ActorIsolation::ActorInstance:
5189
5191
case ActorIsolation::Unspecified:
5190
- case ActorIsolation::Nonisolated:
5191
5192
case ActorIsolation::CallerIsolationInheriting:
5192
5193
case ActorIsolation::NonisolatedUnsafe:
5193
5194
break ;
5195
+ case ActorIsolation::Nonisolated:
5196
+ if (inferredIsolation.source .kind == IsolationSource::Kind::Explicit) {
5197
+ if (!foundIsolation) {
5198
+ // We found an explicitly 'nonisolated' protocol.
5199
+ foundIsolation = {
5200
+ protoIsolation,
5201
+ IsolationSource (proto, IsolationSource::Conformance)};
5202
+ }
5203
+ continue ;
5204
+ } else {
5205
+ break ;
5206
+ }
5194
5207
5195
5208
case ActorIsolation::Erased:
5196
5209
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
@@ -106,6 +106,32 @@ struct A: Refined {
106
106
init ( x: NonSendable ) {
107
107
self . x = x // okay
108
108
}
109
+
110
+ init ( ) {
111
+ self . x = NonSendable ( )
112
+ }
113
+
114
+ func f( ) { }
115
+ }
116
+
117
+ @MainActor protocol ExplicitGlobalActor : Refined { }
118
+
119
+ struct IsolatedStruct : ExplicitGlobalActor {
120
+ // expected-note@+2 {{main actor isolation inferred from conformance to protocol 'ExplicitGlobalActor'}}
121
+ // expected-note@+1 {{calls to instance method 'g()' from outside of its actor context are implicitly asynchronous}}
122
+ func g( ) { }
123
+ }
124
+
125
+ struct NonisolatedStruct {
126
+ func callF( ) {
127
+ return A ( ) . f ( ) // okay, 'A' is non-isolated.
128
+ }
129
+
130
+ // expected-note@+1 {{add '@MainActor' to make instance method 'callG()' part of global actor 'MainActor'}}
131
+ func callG( ) {
132
+ // expected-error@+1{{call to main actor-isolated instance method 'g()' in a synchronous nonisolated context}}
133
+ return IsolatedStruct ( ) . g ( )
134
+ }
109
135
}
110
136
111
137
// MARK: - Extensions
You can’t perform that action at this time.
0 commit comments