Skip to content

Commit 0a237ae

Browse files
committed
[TypeChecker] Make sure that @preconcurrency use is detected in assignments
If destination is marked as `@preconcurrency` the Sendable conformance errors should be downgraded to warnings even in Swift 6 mode just like for member and subscript references. (cherry picked from commit f474588)
1 parent 7da00d4 commit 0a237ae

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3701,6 +3701,11 @@ class ExprAvailabilityWalker : public BaseDiagnosticWalker {
37013701
maybeDiagKeyPath(KP);
37023702
}
37033703
if (auto A = dyn_cast<AssignExpr>(E)) {
3704+
// Attempting to assign to a @preconcurrency declaration should
3705+
// downgrade Sendable conformance mismatches to warnings.
3706+
PreconcurrencyCalleeStack.push_back(
3707+
hasReferenceToPreconcurrencyDecl(A->getDest()));
3708+
37043709
walkAssignExpr(A);
37053710
return Action::SkipChildren(E);
37063711
}

test/Concurrency/predates_concurrency_swift6.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,4 +307,7 @@ do {
307307
// expected-warning@-1 {{type '() -> ()' does not conform to the 'Sendable' protocol}}
308308
// expected-note@-2 {{a function type must be marked '@Sendable' to conform to 'Sendable'}}
309309
}
310+
311+
// If destination is @preconcurrency the Sendable conformance error should be downgraded
312+
d = data // expected-warning {{type 'Any' does not conform to the 'Sendable' protocol}}
310313
}

0 commit comments

Comments
 (0)