Skip to content

Commit 2fd5b5f

Browse files
xedinahoppen
authored andcommitted
[CSGen] Interpolations: Collect all vars referenced in the body to preserve connection to context
Since "tap" bodies are now type-checked together with the context, it's imperative that the variable that represents an interpolation never gets disconnected from its context in the constraint system, otherwise it wouldn't be possible to determine types for the references.
1 parent ac6ea62 commit 2fd5b5f

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1304,14 +1304,26 @@ struct VarRefCollector : public ASTWalker {
13041304

13051305
SmallVector<TypeVariableType *, 2> referencedVars;
13061306

1307-
// If tap expression is located in a closure, let's connect them
1308-
// because interpolation could use parameters.
13091307
if (auto *tap = getAsExpr<TapExpr>(appendingExpr)) {
13101308
auto *tapDC = tap->getVar()->getDeclContext();
1309+
// If tap expression is located in a closure, let's
1310+
// connect them because interpolation could use parameters.
13111311
if (auto *closure = dyn_cast<ClosureExpr>(tapDC)) {
13121312
referencedVars.push_back(
13131313
CS.getType(closure)->castTo<TypeVariableType>());
13141314
}
1315+
1316+
// Collect all of the variable references that appear
1317+
// in the tap body, otherwise tap expression is going
1318+
// to get disconnected from the context.
1319+
if (auto *body = tap->getBody()) {
1320+
VarRefCollector refCollector(CS);
1321+
1322+
body->walk(refCollector);
1323+
1324+
referencedVars.append(refCollector.varRefs.begin(),
1325+
refCollector.varRefs.end());
1326+
}
13151327
}
13161328

13171329
// Must be Conversion; if it's Equal, then in semi-rare cases, the

0 commit comments

Comments
 (0)