Skip to content

Commit e101e9f

Browse files
authored
Merge pull request #58432 from DougGregor/downgrade-sendable-function-conversions-5.7
Downgrade missing @sendable to a warning in Swift 5.x mode.
2 parents 073f733 + ecf2db3 commit e101e9f

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2672,11 +2672,15 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
26722672
}
26732673

26742674
/// Whether to downgrade to a concurrency warning.
2675-
auto isConcurrencyWarning = [&] {
2676-
if (contextRequiresStrictConcurrencyChecking(DC, GetClosureType{*this})
2677-
&& !hasPreconcurrencyCallee(this, locator))
2675+
auto isConcurrencyWarning = [&](bool forSendable) {
2676+
// Except for Sendable warnings, don't downgrade to an error in strict
2677+
// contexts without a preconcurrency callee.
2678+
if (!forSendable &&
2679+
contextRequiresStrictConcurrencyChecking(DC, GetClosureType{*this}) &&
2680+
!hasPreconcurrencyCallee(this, locator))
26782681
return false;
26792682

2683+
// We can only handle the downgrade for conversions.
26802684
switch (kind) {
26812685
case ConstraintKind::Conversion:
26822686
case ConstraintKind::ArgumentConversion:
@@ -2696,7 +2700,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
26962700

26972701
auto *fix = AddSendableAttribute::create(
26982702
*this, func1, func2, getConstraintLocator(locator),
2699-
isConcurrencyWarning());
2703+
isConcurrencyWarning(true));
27002704
if (recordFix(fix))
27012705
return getTypeMatchFailure(locator);
27022706
}
@@ -2731,7 +2735,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
27312735

27322736
auto *fix = MarkGlobalActorFunction::create(
27332737
*this, func1, func2, getConstraintLocator(locator),
2734-
isConcurrencyWarning());
2738+
isConcurrencyWarning(false));
27352739

27362740
if (recordFix(fix))
27372741
return getTypeMatchFailure(locator);

test/Concurrency/sendable_checking.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func testCV(
5959
acceptCV(ns4) // expected-warning{{type 'NS4' does not conform to the 'Sendable' protocol}}
6060
acceptCV(fn) // expected-warning{{type '() -> Void' does not conform to the 'Sendable' protocol}}
6161
// expected-note@-1{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
62-
acceptSendableFn(fn) // expected-error{{passing non-sendable parameter 'fn' to function expecting a @Sendable closure}}
62+
acceptSendableFn(fn) // expected-warning{{passing non-sendable parameter 'fn' to function expecting a @Sendable closure}}
6363
}
6464

6565
// rdar://83942484 - spurious Sendable diagnostics

0 commit comments

Comments
 (0)