Skip to content

Commit f9ec1e6

Browse files
committed
[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 1a7d071 commit f9ec1e6

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
@@ -1272,14 +1272,6 @@ struct VarRefCollector : public ASTWalker {
12721272
SmallVector<TypeVariableType *, 2> referencedVars;
12731273

12741274
if (auto *tap = getAsExpr<TapExpr>(appendingExpr)) {
1275-
auto *tapDC = tap->getVar()->getDeclContext();
1276-
// If tap expression is located in a closure, let's
1277-
// connect them because interpolation could use parameters.
1278-
if (auto *closure = dyn_cast<ClosureExpr>(tapDC)) {
1279-
referencedVars.push_back(
1280-
CS.getType(closure)->castTo<TypeVariableType>());
1281-
}
1282-
12831275
// Collect all of the variable references that appear
12841276
// in the tap body, otherwise tap expression is going
12851277
// to get disconnected from the context.

lib/Sema/CSSyntacticElement.cpp

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

354354
if (locator->directlyAt<TapExpr>()) {
355-
auto *tap = castToExpr<TapExpr>(locator->getAnchor());
356-
auto *tapDC = tap->getVar()->getDeclContext();
357-
358-
referencedVars.push_back(cs.getType(tap)->castTo<TypeVariableType>());
359-
360-
if (auto *closure = dyn_cast<ClosureExpr>(tapDC)) {
361-
referencedVars.push_back(cs.getType(closure)->castTo<TypeVariableType>());
362-
}
363-
364355
// Body of the interpolation is always isolated from its context, only
365356
// its individual elements are allowed access to type information
366357
// 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)