Skip to content

Commit 0dfcf59

Browse files
committed
[IDE] Run RecontextualizeClosures in TypeCheckASTNodeAtLocRequest
1 parent a8dd681 commit 0dfcf59

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/Sema/TypeCheckStmt.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1876,10 +1876,17 @@ bool TypeCheckASTNodeAtLocRequest::evaluate(
18761876
auto i = patternInit->getBindingIndex();
18771877
PBD->getPattern(i)->forEachVariable(
18781878
[](VarDecl *VD) { (void)VD->getInterfaceType(); });
1879-
if (PBD->getInit(i)) {
1879+
if (auto Init = PBD->getInit(i)) {
18801880
if (!PBD->isInitializerChecked(i)) {
18811881
typeCheckPatternBinding(PBD, i,
18821882
/*LeaveClosureBodyUnchecked=*/true);
1883+
// Retrieve the accessor's body to trigger RecontextualizeClosures
1884+
// This is important to get the correct USR of variables defined
1885+
// in closures initializing lazy variables.
1886+
PBD->getPattern(i)->forEachVariable([](VarDecl *VD) {
1887+
VD->visitEmittedAccessors(
1888+
[&](AccessorDecl *accessor) { (void)accessor->getBody(); });
1889+
});
18831890
return false;
18841891
}
18851892
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %sourcekitd-test -req=cursor -pos=5:13 %s -- %s | %FileCheck %s
2+
3+
class MyClass {
4+
lazy var calculatorContext: Int = {
5+
let context = 1
6+
return context
7+
}()
8+
}
9+
10+
// CHECK: s:34cursor_in_closure_initializing_var7MyClassC17calculatorContextSivgSiyXEfU_7contextL_Sivp

0 commit comments

Comments
 (0)