File tree Expand file tree Collapse file tree 2 files changed +31
-3
lines changed
test/SourceKit/CursorInfo Expand file tree Collapse file tree 2 files changed +31
-3
lines changed Original file line number Diff line number Diff line change @@ -37,11 +37,20 @@ void typeCheckDeclAndParentClosures(ValueDecl *VD) {
37
37
// encoded in the USR of ParentContexts in the cursor info response.
38
38
auto DC = VD->getDeclContext ();
39
39
while (DC->getParent ()) {
40
- if (auto Closure = dyn_cast<AbstractClosureExpr>(DC)) {
41
- if (Closure ->getType ().isNull ()) {
40
+ if (auto AbstractClosure = dyn_cast<AbstractClosureExpr>(DC)) {
41
+ if (AbstractClosure ->getType ().isNull ()) {
42
42
typeCheckASTNodeAtLoc (
43
43
TypeCheckASTNodeAtLocContext::declContext (DC->getParent ()),
44
- Closure->getLoc ());
44
+ AbstractClosure->getLoc ());
45
+ }
46
+ if (auto Closure = dyn_cast<ClosureExpr>(AbstractClosure)) {
47
+ // Set the closure's body state to `TypeCheckedWithSignature`. This
48
+ // matches what the type checker is doing when applying the solution and
49
+ // is necessary so the USRs we compute in solver-based cursor info match
50
+ // those in the AST - the critical point is that
51
+ // `isSeparatelyTypeChecked` in `SetLocalDiscriminators::walkToExprPre`
52
+ // needs to evaluate to `false`.
53
+ Closure->setBodyState (ClosureExpr::BodyState::TypeCheckedWithSignature);
45
54
}
46
55
}
47
56
DC = DC->getParent ();
Original file line number Diff line number Diff line change
1
+ func sink( _ a: ( Int ) -> Void ) { }
2
+
3
+ func testSingleStatementClosure( ) {
4
+ sink { items in
5
+ // RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):9 %s -- %s | %FileCheck %s --check-prefix=SINGLE-STMT-CLOSURE
6
+ var items = items
7
+ }
8
+ // SINGLE-STMT-CLOSURE: s:33variable_discriminator_in_closure26testSingleStatementClosureyyFySiXEfU_5itemsL_Sivp
9
+ }
10
+
11
+
12
+ func testMultiStatementClosure( ) {
13
+ sink { items in
14
+ // RUN: %sourcekitd-test -req=cursor -pos=%(line + 1):9 %s -- %s | %FileCheck %s --check-prefix=MULTI-STMT-CLOSURE
15
+ var items = items
16
+ print ( " xxx " )
17
+ }
18
+ // MULTI-STMT-CLOSURE: s:33variable_discriminator_in_closure25testMultiStatementClosureyyFySiXEfU_5itemsL_Sivp
19
+ }
You can’t perform that action at this time.
0 commit comments