File tree Expand file tree Collapse file tree 2 files changed +54
-7
lines changed Expand file tree Collapse file tree 2 files changed +54
-7
lines changed Original file line number Diff line number Diff line change @@ -4603,30 +4603,43 @@ getIsolationFromConformances(NominalTypeDecl *nominal) {
4603
4603
static std::optional<ActorIsolation>
4604
4604
getIsolationFromInheritedProtocols (ProtocolDecl *protocol) {
4605
4605
std::optional<ActorIsolation> foundIsolation;
4606
- for (auto inherited : protocol->getInheritedProtocols ()) {
4607
- switch (auto protoIsolation = getActorIsolation (inherited)) {
4606
+ bool conflict = false ;
4607
+
4608
+ auto inferIsolation = [&](ValueDecl *decl) {
4609
+ switch (auto protoIsolation = getActorIsolation (decl)) {
4608
4610
case ActorIsolation::ActorInstance:
4609
4611
case ActorIsolation::Unspecified:
4610
4612
case ActorIsolation::Nonisolated:
4611
4613
case ActorIsolation::NonisolatedUnsafe:
4612
- break ;
4614
+ return ;
4613
4615
4614
4616
case ActorIsolation::Erased:
4615
4617
llvm_unreachable (" protocol cannot have erased isolation" );
4616
4618
4617
4619
case ActorIsolation::GlobalActor:
4618
4620
if (!foundIsolation) {
4619
4621
foundIsolation = protoIsolation;
4620
- continue ;
4622
+ return ;
4621
4623
}
4622
4624
4623
4625
if (*foundIsolation != protoIsolation)
4624
- return std::nullopt ;
4626
+ conflict = true ;
4625
4627
4626
- break ;
4628
+ return ;
4627
4629
}
4630
+ };
4631
+
4632
+ for (auto inherited : protocol->getInheritedProtocols ()) {
4633
+ inferIsolation (inherited);
4628
4634
}
4629
4635
4636
+ if (auto *superclass = protocol->getSuperclassDecl ()) {
4637
+ inferIsolation (superclass);
4638
+ }
4639
+
4640
+ if (conflict)
4641
+ return std::nullopt;
4642
+
4630
4643
return foundIsolation;
4631
4644
}
4632
4645
Original file line number Diff line number Diff line change 2
2
3
3
// RUN: %target-swift-frontend -swift-version 6 -emit-module -emit-module-path %t/other_global_actor_inference.swiftmodule -module-name other_global_actor_inference -strict-concurrency=complete %S/Inputs/other_global_actor_inference.swift
4
4
5
- // RUN: %target-swift-frontend -swift-version 6 -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify -enable-upcoming-feature GlobalActorIsolatedTypesUsability
5
+ // RUN: %target-swift-frontend -swift-version 6 -I %t -disable-availability-checking %s -emit-sil -o /dev/null -verify
6
6
7
7
// REQUIRES: concurrency
8
8
@@ -179,3 +179,37 @@ extension S3 {
179
179
// expected-error@-1{{global actor 'SomeGlobalActor'-isolated instance method 'f()' cannot be used to satisfy main actor-isolated protocol requirement}}
180
180
//expected-note@-2{{add 'nonisolated' to 'f()' to make this instance method not isolated to the actor}}
181
181
}
182
+
183
+ @MainActor
184
+ func onMain( ) { }
185
+
186
+ @MainActor
187
+ class MainActorSuperclass { }
188
+
189
+ protocol InferMainFromSuperclass : MainActorSuperclass {
190
+ func f( )
191
+ }
192
+
193
+ class C1 : MainActorSuperclass , InferMainFromSuperclass {
194
+ func f( ) {
195
+ onMain ( ) // okay
196
+ }
197
+ }
198
+
199
+ protocol InferenceConflictWithSuperclass : MainActorSuperclass , InferSomeGlobalActor {
200
+ func g( )
201
+ // expected-note@-1 {{mark the protocol requirement 'g()' 'async' to allow actor-isolated conformances}}
202
+ }
203
+
204
+
205
+ class C2 : MainActorSuperclass , InferenceConflictWithSuperclass {
206
+ //expected-note@-1 {{add '@preconcurrency' to the 'InferenceConflictWithSuperclass' conformance to defer isolation checking to run time}}
207
+
208
+ func f( ) { }
209
+
210
+ func g( ) { }
211
+ // expected-error@-1 {{main actor-isolated instance method 'g()' cannot be used to satisfy nonisolated protocol requirement}}
212
+ // expected-note@-2 {{add 'nonisolated' to 'g()' to make this instance method not isolated to the actor}}
213
+ }
214
+
215
+
You can’t perform that action at this time.
0 commit comments