Skip to content

Commit ae93790

Browse files
[Sema] Record the correct RemoveExtranousArguments fix for closure mismatch involving tuple destructuring
1 parent 5db5733 commit ae93790

File tree

1 file changed

+29
-3
lines changed

1 file changed

+29
-3
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4340,8 +4340,34 @@ bool ConstraintSystem::repairFailures(
43404340
// as a narrow exception to SE-0110, see `matchFunctionTypes`.
43414341
//
43424342
// But if `T.Element` didn't get resolved to `Void` we'd like
4343-
// to diagnose this as a missing argument which can't be ignored.
4343+
// to diagnose this as a missing argument which can't be ignored or
4344+
// a tuple is trying to be inferred as a tuple for destructuring but
4345+
// contextual argument does not match(in this case we remove the extra
4346+
// closure arguments).
43444347
if (arg != getTypeVariables().end()) {
4348+
if (auto argToParamElt =
4349+
path.back().getAs<LocatorPathElt::ApplyArgToParam>()) {
4350+
auto loc = getConstraintLocator(anchor, path);
4351+
auto closureAnchor =
4352+
getAsExpr<ClosureExpr>(simplifyLocatorToAnchor(loc));
4353+
if (rhs->is<TupleType>() && closureAnchor &&
4354+
closureAnchor->getParameters()->size() > 1) {
4355+
auto callee = getCalleeLocator(loc);
4356+
auto overload = findSelectedOverloadFor(callee);
4357+
if (overload) {
4358+
auto fnType = overload->openedType->getAs<FunctionType>();
4359+
auto paramIdx = argToParamElt->getParamIdx();
4360+
if (auto paramType = fnType->getParams()[paramIdx]
4361+
.getOldType()
4362+
->getAs<FunctionType>()) {
4363+
conversionsOrFixes.push_back(
4364+
RemoveExtraneousArguments::create(*this, paramType, {}, loc));
4365+
break;
4366+
}
4367+
}
4368+
}
4369+
}
4370+
43454371
conversionsOrFixes.push_back(AddMissingArguments::create(
43464372
*this, {SynthesizedArg{0, AnyFunctionType::Param(*arg)}},
43474373
getConstraintLocator(anchor, path)));
@@ -11216,7 +11242,8 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1121611242
case FixKind::AllowCheckedCastCoercibleOptionalType:
1121711243
case FixKind::AllowUnsupportedRuntimeCheckedCast:
1121811244
case FixKind::AllowAlwaysSucceedCheckedCast:
11219-
case FixKind::AllowInvalidStaticMemberRefOnProtocolMetatype: {
11245+
case FixKind::AllowInvalidStaticMemberRefOnProtocolMetatype:
11246+
case FixKind::RemoveExtraneousArguments: {
1122011247
return recordFix(fix) ? SolutionKind::Error : SolutionKind::Solved;
1122111248
}
1122211249

@@ -11365,7 +11392,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1136511392
case FixKind::AllowTypeOrInstanceMember:
1136611393
case FixKind::AllowInvalidPartialApplication:
1136711394
case FixKind::AllowInvalidInitRef:
11368-
case FixKind::RemoveExtraneousArguments:
1136911395
case FixKind::AllowClosureParameterDestructuring:
1137011396
case FixKind::AllowInaccessibleMember:
1137111397
case FixKind::AllowAnyObjectKeyPathRoot:

0 commit comments

Comments
 (0)