Skip to content

Downgrade missing @Sendable to a warning in Swift 5.x mode. #58433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2672,11 +2672,15 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
}

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

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

auto *fix = AddSendableAttribute::create(
*this, func1, func2, getConstraintLocator(locator),
isConcurrencyWarning());
isConcurrencyWarning(true));
if (recordFix(fix))
return getTypeMatchFailure(locator);
}
Expand Down Expand Up @@ -2731,7 +2735,7 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,

auto *fix = MarkGlobalActorFunction::create(
*this, func1, func2, getConstraintLocator(locator),
isConcurrencyWarning());
isConcurrencyWarning(false));

if (recordFix(fix))
return getTypeMatchFailure(locator);
Expand Down
2 changes: 1 addition & 1 deletion test/Concurrency/sendable_checking.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func testCV(
acceptCV(ns4) // expected-warning{{type 'NS4' does not conform to the 'Sendable' protocol}}
acceptCV(fn) // expected-warning{{type '() -> Void' does not conform to the 'Sendable' protocol}}
// expected-note@-1{{a function type must be marked '@Sendable' to conform to 'Sendable'}}
acceptSendableFn(fn) // expected-error{{passing non-sendable parameter 'fn' to function expecting a @Sendable closure}}
acceptSendableFn(fn) // expected-warning{{passing non-sendable parameter 'fn' to function expecting a @Sendable closure}}
}

// rdar://83942484 - spurious Sendable diagnostics
Expand Down