Skip to content

Commit e32fd8a

Browse files
committed
[Concurrency] Downgrade errors about actor-isolated witnesses to warnings until
Swift 6 when the witness is a non-Sendable 'let'.
1 parent 60807a7 commit e32fd8a

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,6 +3233,19 @@ ConformanceChecker::checkActorIsolation(ValueDecl *requirement,
32333233
witness->getInnermostDeclContext()).defaultDiagnosticBehavior();
32343234
}
32353235

3236+
// If the witness is a non-Sendable 'let', compiler versions <= 5.10
3237+
// didn't diagnose this code, so downgrade the error to an warning
3238+
// until Swift 6.
3239+
if (auto *var = dyn_cast<VarDecl>(witness)) {
3240+
ActorReferenceResult::Options options = llvm::None;
3241+
isLetAccessibleAnywhere(
3242+
witness->getDeclContext()->getParentModule(),
3243+
var, options);
3244+
if (options.contains(ActorReferenceResult::Flags::Preconcurrency)) {
3245+
behavior = DiagnosticBehavior::Warning;
3246+
}
3247+
}
3248+
32363249
// Complain that this witness cannot conform to the requirement due to
32373250
// actor isolation.
32383251
witness->diagnose(diag::actor_isolated_witness,

test/Concurrency/actor_isolation.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1543,6 +1543,15 @@ class OverridesNonsiolatedInit: SuperWithNonisolatedInit {
15431543
// expected-note@+1 {{class 'NonSendable' does not conform to the 'Sendable' protocol}}
15441544
class NonSendable {}
15451545

1546+
protocol NonisolatedProtocol {
1547+
var ns: NonSendable { get } // expected-note {{'ns' declared here}}
1548+
}
1549+
1550+
actor ActorWithNonSendableLet: NonisolatedProtocol {
1551+
// expected-warning@+1 {{actor-isolated property 'ns' cannot be used to satisfy nonisolated protocol requirement; this is an error in Swift 6}}
1552+
let ns = NonSendable()
1553+
}
1554+
15461555
actor ProtectNonSendable {
15471556
// expected-note@+1 2 {{property declared here}}
15481557
let ns = NonSendable()

0 commit comments

Comments
 (0)