@@ -6569,25 +6569,29 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
6569
6569
6570
6570
auto *paramList = closure->getParameters ();
6571
6571
for (unsigned i = 0 , n = paramList->size (); i != n; ++i) {
6572
- const auto * param = paramList-> get (i) ;
6572
+ const auto & param = closureType-> getParams ()[i] ;
6573
6573
6574
- Type externalType = closureType->getParams ()[i].getOldType ();
6575
6574
Type internalType;
6576
6575
6577
- if (param->getTypeRepr ()) {
6578
- internalType = externalType;
6576
+ if (paramList->get (i)->getTypeRepr ()) {
6577
+ // Internal type is the type used in the body of the closure,
6578
+ // so "external" type translates to it as follows:
6579
+ // - `Int...` -> `[Int]`,
6580
+ // - `inout Int` -> `@lvalue Int`.
6581
+ internalType = param.getParameterType ();
6579
6582
} else {
6580
6583
auto *paramLoc =
6581
6584
getConstraintLocator (closure, LocatorPathElt::TupleElement (i));
6582
6585
6583
6586
internalType = createTypeVariable (paramLoc, TVO_CanBindToLValue |
6584
6587
TVO_CanBindToNoEscape);
6585
6588
6589
+ auto externalType = param.getOldType ();
6586
6590
addConstraint (ConstraintKind::BindParam, externalType, internalType,
6587
6591
paramLoc);
6588
6592
}
6589
6593
6590
- setType (param , internalType);
6594
+ setType (paramList-> get (i) , internalType);
6591
6595
}
6592
6596
6593
6597
assignFixedType (typeVar, closureType, closureLocator);
0 commit comments