Skip to content

Commit e4277da

Browse files
authored
Merge pull request swiftlang#29252 from xedin/rdar-58647769
[ConstraintSystem] Fix conversion of variadic/inout closure parameter…
2 parents 80d6230 + f49d450 commit e4277da

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6569,25 +6569,29 @@ bool ConstraintSystem::resolveClosure(TypeVariableType *typeVar,
65696569

65706570
auto *paramList = closure->getParameters();
65716571
for (unsigned i = 0, n = paramList->size(); i != n; ++i) {
6572-
const auto *param = paramList->get(i);
6572+
const auto &param = closureType->getParams()[i];
65736573

6574-
Type externalType = closureType->getParams()[i].getOldType();
65756574
Type internalType;
65766575

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();
65796582
} else {
65806583
auto *paramLoc =
65816584
getConstraintLocator(closure, LocatorPathElt::TupleElement(i));
65826585

65836586
internalType = createTypeVariable(paramLoc, TVO_CanBindToLValue |
65846587
TVO_CanBindToNoEscape);
65856588

6589+
auto externalType = param.getOldType();
65866590
addConstraint(ConstraintKind::BindParam, externalType, internalType,
65876591
paramLoc);
65886592
}
65896593

6590-
setType(param, internalType);
6594+
setType(paramList->get(i), internalType);
65916595
}
65926596

65936597
assignFixedType(typeVar, closureType, closureLocator);

test/Constraints/closures.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,3 +942,8 @@ class Foo<State: StateType> {
942942
})
943943
}
944944
}
945+
946+
// Make sure that `String...` is translated into `[String]` in the body
947+
func test_explicit_variadic_is_interpreted_correctly() {
948+
_ = { (T: String...) -> String in T[0] + "" } // Ok
949+
}

0 commit comments

Comments
 (0)