Skip to content

Commit c479a0c

Browse files
committed
[Sema] Fix batch-mode-only lazy var bug
The temporary variable used by string interpolation needs to be recontextualized when it’s inserted into a synthesized getter. Fixes a compilation failure in Alamofire. I’ll probably follow up on this bug a bit more after merging.
1 parent d79f7ce commit c479a0c

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1205,6 +1205,16 @@ namespace {
12051205
CLE.Init->setDeclContext(NewDC);
12061206
}
12071207
}
1208+
1209+
// Unlike a closure, a TapExpr is not a DeclContext, so we need to
1210+
// recontextualize its variable and then anything else in its body.
1211+
// FIXME: Might be better to change walkToDeclPre() and walkToStmtPre()
1212+
// below, but I don't know what other effects that might have.
1213+
if (auto TE = dyn_cast<TapExpr>(E)) {
1214+
TE->getVar()->setDeclContext(NewDC);
1215+
for (auto node : TE->getBody()->getElements())
1216+
node.walk(RecontextualizeClosures(NewDC));
1217+
}
12081218

12091219
return { true, E };
12101220
}

test/decl/var/Inputs/lazy_properties_batch_mode_b.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,7 @@ struct B {
33
lazy var crash: String = {
44
return ""
55
}()
6+
lazy var interpolatingMinimal: String = "Hello, \(1)!"
7+
lazy var interpolatingTorture: String = "Hello, \( "\( "name" )" )\( { "!" }() )"
68
}
79

0 commit comments

Comments
 (0)