@@ -3236,6 +3236,16 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
32363236 return getTypeMatchFailure(locator);
32373237 }
32383238
3239+ // () -> sending T can be a subtype of () -> T... but not vis-a-versa.
3240+ if (func1->hasSendingResult() != func2->hasSendingResult() &&
3241+ (!func1->hasSendingResult() || kind < ConstraintKind::Subtype)) {
3242+ auto *fix = AllowSendingMismatch::create(
3243+ *this, getConstraintLocator(locator), func1, func2,
3244+ AllowSendingMismatch::Kind::Result);
3245+ if (recordFix(fix))
3246+ return getTypeMatchFailure(locator);
3247+ }
3248+
32393249 if (!matchFunctionIsolations(func1, func2, kind, flags, locator))
32403250 return getTypeMatchFailure(locator);
32413251
@@ -3666,6 +3676,17 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
36663676 return getTypeMatchFailure(argumentLocator);
36673677 }
36683678
3679+ // Do not allow for functions that expect a sending parameter to match
3680+ // with a function that expects a non-sending parameter.
3681+ if (func1Param.getParameterFlags().isSending() &&
3682+ !func2Param.getParameterFlags().isSending()) {
3683+ auto *fix = AllowSendingMismatch::create(
3684+ *this, getConstraintLocator(argumentLocator), func1, func2,
3685+ AllowSendingMismatch::Kind::Parameter);
3686+ if (recordFix(fix))
3687+ return getTypeMatchFailure(argumentLocator);
3688+ }
3689+
36693690 // FIXME: We should check value ownership too, but it's not completely
36703691 // trivial because of inout-to-pointer conversions.
36713692
@@ -11770,10 +11791,10 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1177011791 if (contextualParam->isIsolated() && !flags.isIsolated() && paramDecl)
1177111792 isolatedParams.insert(paramDecl);
1177211793
11773- param =
11774- param.withFlags(flags.withInOut( contextualParam->isInOut ())
11775- .withVariadic (contextualParam->isVariadic ())
11776- .withIsolated (contextualParam->isIsolated ()));
11794+ param = param.withFlags(flags.withInOut(contextualParam->isInOut())
11795+ .withVariadic( contextualParam->isVariadic ())
11796+ .withIsolated (contextualParam->isIsolated ())
11797+ .withSending (contextualParam->isSending ()));
1177711798 }
1177811799 }
1177911800
@@ -11900,6 +11921,12 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1190011921 closureExtInfo = closureExtInfo.withSendable();
1190111922 }
1190211923
11924+ // Propagate sending result from the contextual type to the closure.
11925+ if (auto contextualFnType = contextualType->getAs<FunctionType>()) {
11926+ if (contextualFnType->hasExtInfo() && contextualFnType->hasSendingResult())
11927+ closureExtInfo = closureExtInfo.withSendingResult();
11928+ }
11929+
1190311930 // Isolated parameters override any other kind of isolation we might infer.
1190411931 if (hasIsolatedParam) {
1190511932 closureExtInfo = closureExtInfo.withIsolation(
@@ -15098,6 +15125,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1509815125 }
1509915126 }
1510015127
15128+ case FixKind::AllowSendingMismatch:
1510115129 case FixKind::InsertCall:
1510215130 case FixKind::RemoveReturn:
1510315131 case FixKind::RemoveAddressOf:
0 commit comments