[ConstraintSystem] Fix conversion of variadic/inout closure parameters for internal use

Delayed constraint generation for the body of the single-statement
closures regressed variadic parameter handling. Fix it by using
`FunctionType::Param::getParameterType` for "internal" version of
the parameter type which translates variadic/inout correctly.

Resolved: rdar://problem/58647769
This commit is contained in:
Pavel Yaskevich
2020-01-16 10:37:32 -08:00
parent 8269522f86
commit f49d4501f8
2 changed files with 14 additions and 5 deletions

View File

@@ -6569,13 +6569,16 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
auto *paramList = closure->getParameters();
for (unsigned i = 0, n = paramList->size(); i != n; ++i) {
const auto *param = paramList->get(i);
const auto &param = closureType->getParams()[i];
Type externalType = closureType->getParams()[i].getOldType();
Type internalType;
if (param->getTypeRepr()) {
internalType = externalType;
if (paramList->get(i)->getTypeRepr()) {
// Internal type is the type used in the body of the closure,
// so "external" type translates to it as follows:
// - `Int...` -> `[Int]`,
// - `inout Int` -> `@lvalue Int`.
internalType = param.getParameterType();
} else {
auto *paramLoc =
getConstraintLocator(closure, LocatorPathElt::TupleElement(i));
@@ -6583,11 +6586,12 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
internalType = createTypeVariable(paramLoc, TVO_CanBindToLValue |
TVO_CanBindToNoEscape);
auto externalType = param.getOldType();
addConstraint(ConstraintKind::BindParam, externalType, internalType,
paramLoc);
}
setType(param, internalType);
setType(paramList->get(i), internalType);
}
assignFixedType(typeVar, closureType, closureLocator);