mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ConstraintSystem] Fix closure parameter destructuring
Detect and fix closure parameter destructuring where
it's not currently allowed e.g. free standing closures
with contextual type `let _: ((Int, Int)) -> Void = { $0 + $1 }`
This commit is contained in:
@@ -1288,8 +1288,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
||||
return elt.getKind() != ConstraintLocator::OptionalPayload;
|
||||
});
|
||||
|
||||
auto &ctx = getASTContext();
|
||||
if (last != path.rend()) {
|
||||
auto &ctx = getASTContext();
|
||||
if (last->getKind() == ConstraintLocator::ApplyArgToParam) {
|
||||
if (isSingleTupleParam(ctx, func2Params) &&
|
||||
canImplodeParams(func1Params)) {
|
||||
@@ -1310,6 +1310,20 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldAttemptFixes()) {
|
||||
auto *anchor = locator.trySimplifyToExpr();
|
||||
if (anchor && isa<ClosureExpr>(anchor) &&
|
||||
isSingleTupleParam(ctx, func2Params) &&
|
||||
canImplodeParams(func1Params)) {
|
||||
auto *fix = AllowClosureParamDestructuring::create(
|
||||
*this, func2, getConstraintLocator(anchor));
|
||||
if (recordFix(fix))
|
||||
return getTypeMatchFailure(argumentLocator);
|
||||
|
||||
implodeParams(func1Params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// https://bugs.swift.org/browse/SR-6796
|
||||
@@ -5779,6 +5793,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
|
||||
case FixKind::AllowTypeOrInstanceMember:
|
||||
case FixKind::AllowInvalidPartialApplication:
|
||||
case FixKind::AllowInvalidInitRef:
|
||||
case FixKind::AllowClosureParameterDestructuring:
|
||||
llvm_unreachable("handled elsewhere");
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user