Skip to content

Commit 8f14126

Browse files
committed
[CSGen] Give a correct locator to each type var representing closure parameter
Fixes a bug where all of the type variables related to closure parameters without type would be attached to the same locator.
1 parent 3100088 commit 8f14126

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

lib/Sema/CSGen.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,9 +1926,13 @@ namespace {
19261926

19271927
/// Give each parameter in a ClosureExpr a fresh type variable if parameter
19281928
/// types were not specified, and return the eventual function type.
1929-
Type getTypeForParameterList(ParameterList *params,
1930-
ConstraintLocatorBuilder locator) {
1931-
for (auto param : *params) {
1929+
Type getTypeForParameterList(ClosureExpr *closureExpr) {
1930+
auto *params = closureExpr->getParameters();
1931+
for (auto i : indices(params->getArray())) {
1932+
auto *param = params->get(i);
1933+
auto *locator = CS.getConstraintLocator(
1934+
closureExpr, LocatorPathElt::getTupleElement(i));
1935+
19321936
// If a type was explicitly specified, use its opened type.
19331937
if (auto type = param->getTypeLoc().getType()) {
19341938
// FIXME: Need a better locator for a pattern as a base.
@@ -1940,9 +1944,8 @@ namespace {
19401944
}
19411945

19421946
// Otherwise, create a fresh type variable.
1943-
Type ty = CS.createTypeVariable(CS.getConstraintLocator(locator),
1944-
TVO_CanBindToInOut);
1945-
1947+
Type ty = CS.createTypeVariable(locator, TVO_CanBindToInOut);
1948+
19461949
param->setType(ty);
19471950
param->setInterfaceType(ty);
19481951
}
@@ -2286,12 +2289,7 @@ namespace {
22862289

22872290
// Give each parameter in a ClosureExpr a fresh type variable if parameter
22882291
// types were not specified, and return the eventual function type.
2289-
auto paramTy = getTypeForParameterList(
2290-
expr->getParameters(),
2291-
CS.getConstraintLocator(
2292-
expr,
2293-
LocatorPathElt::getTupleElement(0)));
2294-
2292+
auto paramTy = getTypeForParameterList(expr);
22952293
auto extInfo = FunctionType::ExtInfo();
22962294

22972295
if (closureCanThrow(expr))

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3094,7 +3094,6 @@ void ConstraintSystem::print(raw_ostream &out) {
30943094
out << "Type Variables:\n";
30953095
for (auto tv : TypeVariables) {
30963096
out.indent(2);
3097-
out << '#' << tv->getID() << " = ";
30983097
tv->getImpl().print(out);
30993098
if (tv->getImpl().canBindToLValue())
31003099
out << " [lvalue allowed]";
@@ -3112,6 +3111,12 @@ void ConstraintSystem::print(raw_ostream &out) {
31123111
out << " equivalent to ";
31133112
rep->print(out);
31143113
}
3114+
3115+
if (auto *locator = tv->getImpl().getLocator()) {
3116+
out << " @ ";
3117+
locator->dump(&TC.Context.SourceMgr, out);
3118+
}
3119+
31153120
out << "\n";
31163121
}
31173122

0 commit comments

Comments
 (0)