@@ -3235,6 +3235,16 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
32353235 return getTypeMatchFailure(locator);
32363236 }
32373237
3238+ // () -> sending T can be a subtype of () -> T... but not vis-a-versa.
3239+ if (func1->hasSendingResult() != func2->hasSendingResult() &&
3240+ (!func1->hasSendingResult() || kind < ConstraintKind::Subtype)) {
3241+ auto *fix = AllowSendingMismatch::create(
3242+ *this, getConstraintLocator(locator), func1, func2,
3243+ AllowSendingMismatch::Kind::Result);
3244+ if (recordFix(fix))
3245+ return getTypeMatchFailure(locator);
3246+ }
3247+
32383248 if (!matchFunctionIsolations(func1, func2, kind, flags, locator))
32393249 return getTypeMatchFailure(locator);
32403250
@@ -3665,6 +3675,17 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
36653675 return getTypeMatchFailure(argumentLocator);
36663676 }
36673677
3678+ // Do not allow for functions that expect a sending parameter to match
3679+ // with a function that expects a non-sending parameter.
3680+ if (func1Param.getParameterFlags().isSending() &&
3681+ !func2Param.getParameterFlags().isSending()) {
3682+ auto *fix = AllowSendingMismatch::create(
3683+ *this, getConstraintLocator(argumentLocator), func1, func2,
3684+ AllowSendingMismatch::Kind::Parameter);
3685+ if (recordFix(fix))
3686+ return getTypeMatchFailure(argumentLocator);
3687+ }
3688+
36683689 // FIXME: We should check value ownership too, but it's not completely
36693690 // trivial because of inout-to-pointer conversions.
36703691
@@ -11785,10 +11806,10 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1178511806 if (contextualParam->isIsolated() && !flags.isIsolated() && paramDecl)
1178611807 isolatedParams.insert(paramDecl);
1178711808
11788- param =
11789- param.withFlags(flags.withInOut( contextualParam->isInOut ())
11790- .withVariadic (contextualParam->isVariadic ())
11791- .withIsolated (contextualParam->isIsolated ()));
11809+ param = param.withFlags(flags.withInOut(contextualParam->isInOut())
11810+ .withVariadic( contextualParam->isVariadic ())
11811+ .withIsolated (contextualParam->isIsolated ())
11812+ .withSending (contextualParam->isSending ()));
1179211813 }
1179311814 }
1179411815
@@ -11915,6 +11936,12 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
1191511936 closureExtInfo = closureExtInfo.withSendable();
1191611937 }
1191711938
11939+ // Propagate sending result from the contextual type to the closure.
11940+ if (auto contextualFnType = contextualType->getAs<FunctionType>()) {
11941+ if (contextualFnType->hasExtInfo() && contextualFnType->hasSendingResult())
11942+ closureExtInfo = closureExtInfo.withSendingResult();
11943+ }
11944+
1191811945 // Isolated parameters override any other kind of isolation we might infer.
1191911946 if (hasIsolatedParam) {
1192011947 closureExtInfo = closureExtInfo.withIsolation(
@@ -15113,6 +15140,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1511315140 }
1511415141 }
1511515142
15143+ case FixKind::AllowSendingMismatch:
1511615144 case FixKind::InsertCall:
1511715145 case FixKind::RemoveReturn:
1511815146 case FixKind::RemoveAddressOf:
0 commit comments