File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change @@ -4912,6 +4912,13 @@ getIsolationFromConformances(NominalTypeDecl *nominal) {
4912
4912
if (isa<ProtocolDecl>(nominal))
4913
4913
return std::nullopt;
4914
4914
4915
+ if (nominal->getAttrs ().getAttribute <NonisolatedAttr>()) {
4916
+ return InferredActorIsolation {
4917
+ getActorIsolationOfContext (nominal->getDeclContext ()),
4918
+ IsolationSource (nominal, IsolationSource::LexicalContext)
4919
+ };
4920
+ }
4921
+
4915
4922
std::optional<InferredActorIsolation> foundIsolation;
4916
4923
for (auto conformance :
4917
4924
nominal->getLocalConformances (ConformanceLookupKind::NonStructural)) {
@@ -5467,14 +5474,6 @@ InferredActorIsolation ActorIsolationRequest::evaluate(
5467
5474
value->getAttrs ().add (preconcurrency);
5468
5475
}
5469
5476
5470
- // If this declaration is non-isolated, we are done.
5471
- auto ctxIsolation = getActorIsolationOfContext (dc);
5472
- if (ctxIsolation.isNonisolated ()) {
5473
- return {
5474
- ctxIsolation,
5475
- IsolationSource (dc->getAsDecl (), IsolationSource::LexicalContext)};
5476
- }
5477
-
5478
5477
if (FuncDecl *fd = dyn_cast<FuncDecl>(value)) {
5479
5478
// Main.main() and Main.$main are implicitly MainActor-protected.
5480
5479
// Any other isolation is an error.
Original file line number Diff line number Diff line change @@ -47,6 +47,17 @@ nonisolated struct NonisolatedStruct: GloballyIsolated {
47
47
struct Nested { } // 'Nested' is not @MainActor-isolated
48
48
}
49
49
50
+ // expected-note@+1 {{calls to global function 'requireMain()' from outside of its actor context are implicitly asynchronous}}
51
+ @MainActor func requireMain( ) { }
52
+
53
+ nonisolated struct S1 : GloballyIsolated {
54
+ var x : NonSendable
55
+ func f( ) {
56
+ // expected-error@+1 {{call to main actor-isolated global function 'requireMain()' in a synchronous nonisolated context}}
57
+ requireMain ( )
58
+ }
59
+ }
60
+
50
61
// MARK: - Protocols
51
62
52
63
nonisolated protocol Refined : GloballyIsolated { }
You can’t perform that action at this time.
0 commit comments