Skip to content

Commit e7a559f

Browse files
authored
Merge pull request #58427 from DougGregor/downgrade-sendable-function-conversions
2 parents d346977 + 1c55138 commit e7a559f

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
@@ -2670,11 +2670,15 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
26702670
}
26712671

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

2681+
// We can only handle the downgrade for conversions.
26782682
switch (kind) {
26792683
case ConstraintKind::Conversion:
26802684
case ConstraintKind::ArgumentConversion:
@@ -2694,7 +2698,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
26942698

26952699
auto *fix = AddSendableAttribute::create(
26962700
*this, func1, func2, getConstraintLocator(locator),
2697-
isConcurrencyWarning());
2701+
isConcurrencyWarning(true));
26982702
if (recordFix(fix))
26992703
return getTypeMatchFailure(locator);
27002704
}
@@ -2729,7 +2733,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
27292733

27302734
auto *fix = MarkGlobalActorFunction::create(
27312735
*this, func1, func2, getConstraintLocator(locator),
2732-
isConcurrencyWarning());
2736+
isConcurrencyWarning(false));
27332737

27342738
if (recordFix(fix))
27352739
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)