[CSFix] SE-0470: Warn about missing @Sendable for unapplied static member references until future Swift version

Static member referenced were marked as `@Sendable` by `InferSendableFromCaptures`
because metatypes used to be always Sendable which is no longer the case, so in
order to maintain the source compatibility we need to downgrade missing `@Sendable`
to a warning for unapplied static member references.

This affects primarily operators at the moment because other static members
form a curry thunk with a call inside and would be diagnosed as a capture.

Resolves: rdar://150777469
This commit is contained in:
Pavel Yaskevich
2025-05-06 16:11:08 -07:00
parent 69f8a6fefa
commit a57310b61d
2 changed files with 49 additions and 1 deletions

View File

@@ -282,10 +282,30 @@ getConcurrencyFixBehavior(ConstraintSystem &cs, ConstraintKind constraintKind,
// We can only handle the downgrade for conversions.
switch (constraintKind) {
case ConstraintKind::Conversion:
case ConstraintKind::ArgumentConversion:
case ConstraintKind::Subtype:
break;
case ConstraintKind::ArgumentConversion: {
if (!forSendable)
break;
// Passing a static member reference as an argument needs to be downgraded
// to a warning until future major mode to maintain source compatibility for
// code with non-Sendable metatypes.
if (!cs.getASTContext().LangOpts.isSwiftVersionAtLeast(7)) {
auto *argLoc = cs.getConstraintLocator(locator);
if (auto *argument = getAsExpr(simplifyLocatorToAnchor(argLoc))) {
if (auto overload = cs.findSelectedOverloadFor(
argument->getSemanticsProvidingExpr())) {
auto *decl = overload->choice.getDecl();
if (decl && decl->isStatic())
return FixBehavior::DowngradeToWarning;
}
}
}
break;
}
default:
if (!cs.shouldAttemptFixes())
return std::nullopt;