Skip to content

Commit 6e9a77b

Browse files
committed
[Concurrency] Fix disallowed override isolation to carry @preconcurrency bit
If ObjC member cannot be overridden due to isolation mismatch set `@preconcurrency` bit to make the diagnostic a warning instead of an error in Swift 5 mode. Resolves: rdar://130776220 Such declarations don't have an explicit attribute to indicate that they are `@preconcurrency` but default isolation as determined by `ActorIsolationRequest` should mark them as such regardless. Resolves: rdar://130776220
1 parent 427077b commit 6e9a77b

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5284,7 +5284,12 @@ ActorIsolation ActorIsolationRequest::evaluate(
52845284
break;
52855285

52865286
case OverrideIsolationResult::Disallowed:
5287-
inferred = *overriddenIso;
5287+
if (overriddenValue->hasClangNode() &&
5288+
overriddenIso->isUnspecified()) {
5289+
inferred = overriddenIso->withPreconcurrency(true);
5290+
} else {
5291+
inferred = *overriddenIso;
5292+
}
52885293
break;
52895294
}
52905295
}

test/ClangImporter/objc_isolation_complete.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,16 @@ class IsolatedSub: NXSender {
3131
return mainActorState
3232
}
3333
}
34+
35+
@objc
36+
@MainActor
37+
class Test : NSObject {
38+
static var shared: Test? // expected-note {{mutation of this static property is only permitted within the actor}}
39+
40+
override init() {
41+
super.init()
42+
43+
Self.shared = self
44+
// expected-warning@-1 {{main actor-isolated static property 'shared' can not be mutated from a nonisolated context; this is an error in the Swift 6 language mode}}
45+
}
46+
}

0 commit comments

Comments
 (0)