Skip to content

Commit f18382c

Browse files
committed
Don't infer 'nonisolated' on stored properties.
Fixes rdar://80424675.
1 parent cc7904c commit f18382c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,6 +3266,13 @@ ActorIsolation ActorIsolationRequest::evaluate(
32663266
ASTContext &ctx = value->getASTContext();
32673267
switch (inferred) {
32683268
case ActorIsolation::Independent:
3269+
// Stored properties cannot be non-isolated, so don't infer it.
3270+
if (auto var = dyn_cast<VarDecl>(value)) {
3271+
if (!var->isStatic() && var->hasStorage())
3272+
return ActorIsolation::forUnspecified();
3273+
}
3274+
3275+
32693276
if (onlyGlobal)
32703277
return ActorIsolation::forUnspecified();
32713278

test/Concurrency/global_actor_inference.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,17 @@ func testNotAllInP1(nap1: NotAllInP1) { // expected-note{{add '@SomeGlobalActor'
9494
nap1.other() // okay
9595
}
9696

97+
// Make sure we don't infer 'nonisolated' for stored properties.
98+
@MainActor
99+
protocol Interface {
100+
nonisolated var baz: Int { get } // expected-note{{'baz' declared here}}
101+
}
102+
103+
@MainActor
104+
class Object: Interface {
105+
var baz: Int = 42 // expected-warning{{property 'baz' isolated to global actor 'MainActor' can not satisfy corresponding requirement from protocol 'Interface'}}
106+
}
107+
97108

98109
// ----------------------------------------------------------------------
99110
// Global actor inference for classes and extensions

0 commit comments

Comments
 (0)