Skip to content

Commit 77bd8ad

Browse files
xedinahoppen
authored andcommitted
[CSGen/SyntaticElement] Remove logic that connects tap expressions to closures
Both single- and multi-statement closures now use variable reference collector to identify variables used in the interpolation body, which means that it's not longer necessary to connect to the closure explicitly (if interpolation is contained in one).
1 parent ff0c942 commit 77bd8ad

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

lib/Sema/CSGen.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,14 +1305,6 @@ struct VarRefCollector : public ASTWalker {
13051305
SmallVector<TypeVariableType *, 2> referencedVars;
13061306

13071307
if (auto *tap = getAsExpr<TapExpr>(appendingExpr)) {
1308-
auto *tapDC = tap->getVar()->getDeclContext();
1309-
// If tap expression is located in a closure, let's
1310-
// connect them because interpolation could use parameters.
1311-
if (auto *closure = dyn_cast<ClosureExpr>(tapDC)) {
1312-
referencedVars.push_back(
1313-
CS.getType(closure)->castTo<TypeVariableType>());
1314-
}
1315-
13161308
// Collect all of the variable references that appear
13171309
// in the tap body, otherwise tap expression is going
13181310
// to get disconnected from the context.

lib/Sema/CSSyntacticElement.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -360,15 +360,6 @@ static void createConjunction(ConstraintSystem &cs,
360360
}
361361

362362
if (locator->directlyAt<TapExpr>()) {
363-
auto *tap = castToExpr<TapExpr>(locator->getAnchor());
364-
auto *tapDC = tap->getVar()->getDeclContext();
365-
366-
referencedVars.push_back(cs.getType(tap)->castTo<TypeVariableType>());
367-
368-
if (auto *closure = dyn_cast<ClosureExpr>(tapDC)) {
369-
referencedVars.push_back(cs.getType(closure)->castTo<TypeVariableType>());
370-
}
371-
372363
// Body of the interpolation is always isolated from its context, only
373364
// its individual elements are allowed access to type information
374365
// from the outside e.g. external declaration references.

test/Sema/string_interpolations.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,16 @@ do {
4343
}
4444
}
4545
}
46+
47+
// This case is (currently) interesting because "\(query)" is type-checked
48+
// separately as part of ~= operator application.
49+
func test_interpolation_in_case(query: String) {
50+
_ = { (request: String) in
51+
switch request {
52+
case "\(query)": // Ok
53+
break
54+
default:
55+
break
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)