Skip to content

Commit ef4624b

Browse files
author
Nathan Hawes
authored
Merge pull request #14171 from nathawes/rdar36871908-cursor-info-crash-on-ivar-of-generic-context-used-in-if-or-for
[CursorInfo] Fix crash on instance variables used directly in if or for when declared in a generic context
2 parents d6c7736 + 80e10b1 commit ef4624b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

lib/IDE/SwiftSourceDocInfo.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ bool CursorInfoResolver::walkToExprPre(Expr *E) {
192192
ContainerType = SAE->getBase()->getType();
193193
}
194194
} else if (auto ME = dyn_cast<MemberRefExpr>(E)) {
195-
SourceLoc DotLoc = ME->getDotLoc();
196-
if (DotLoc.isValid() && DotLoc.getAdvancedLoc(1) == LocToResolve) {
195+
SourceLoc MemberLoc = ME->getNameLoc().getBaseNameLoc();
196+
if (MemberLoc.isValid() && MemberLoc == LocToResolve) {
197197
ContainerType = ME->getBase()->getType();
198198
}
199199
}

test/SourceKit/CursorInfo/cursor_generics.swift

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ func someFunc <A>() -> A {
99
fatalError()
1010
}
1111

12+
// rdar://problem/36871908
13+
class MyType<T> {
14+
let test: Bool = false
15+
let items: [Int] = []
16+
func myMethod() {
17+
if test {}
18+
for i in items {}
19+
}
20+
}
21+
1222
// RUN: %sourcekitd-test -req=cursor -pos=1:10 %s -- %s | %FileCheck -check-prefix=CHECK1 %s
1323
// CHECK1: <Declaration>func testGenerics&lt;T&gt;(x: <Type usr="s:15cursor_generics12testGenerics1xyx_tlF1TL_xmfp">T</Type>)</Declaration>
1424

@@ -19,3 +29,11 @@ func someFunc <A>() -> A {
1929
// RUN: %sourcekitd-test -req=cursor -pos=8:16 %s -- %s | %FileCheck -check-prefix=CHECK3 %s
2030
// CHECK3: source.lang.swift.decl.generic_type_param
2131
// CHECK3: <Declaration>A</Declaration>
32+
33+
// RUN: %sourcekitd-test -req=cursor -pos=17:8 %s -- %s | %FileCheck -check-prefix=CHECK4 %s
34+
// CHECK4: source.lang.swift.ref.var.instance
35+
// CHECK4: <Declaration>let test: <Type usr="s:Sb">Bool</Type></Declaration>
36+
37+
// RUN: %sourcekitd-test -req=cursor -pos=18:14 %s -- %s | %FileCheck -check-prefix=CHECK5 %s
38+
// CHECK5: source.lang.swift.ref.var.instance
39+
// CHECK5: <Declaration>let items: [<Type usr="s:Si">Int</Type>]</Declaration>

0 commit comments

Comments
 (0)