mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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 ¶m = 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);
|
||||
|
||||
Reference in New Issue
Block a user