Skip to content

Commit f474588

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.
1 parent aa0b356 commit f474588

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
@@ -3671,6 +3671,11 @@ class ExprAvailabilityWalker : public BaseDiagnosticWalker {
36713671
maybeDiagKeyPath(KP);
36723672
}
36733673
if (auto A = dyn_cast<AssignExpr>(E)) {
3674+
// Attempting to assign to a @preconcurrency declaration should
3675+
// downgrade Sendable conformance mismatches to warnings.
3676+
PreconcurrencyCalleeStack.push_back(
3677+
hasReferenceToPreconcurrencyDecl(A->getDest()));
3678+
36743679
walkAssignExpr(A);
36753680
return Action::SkipChildren(E);
36763681
}

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)