Skip to content

[4.1][CursorInfo] Fix crash on instance variables used directly in if or for when declared in a generic context #14190

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/IDE/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ bool CursorInfoResolver::walkToExprPre(Expr *E) {
ContainerType = SAE->getBase()->getType();
}
} else if (auto ME = dyn_cast<MemberRefExpr>(E)) {
SourceLoc DotLoc = ME->getDotLoc();
if (DotLoc.isValid() && DotLoc.getAdvancedLoc(1) == LocToResolve) {
SourceLoc MemberLoc = ME->getNameLoc().getBaseNameLoc();
if (MemberLoc.isValid() && MemberLoc == LocToResolve) {
ContainerType = ME->getBase()->getType();
}
}
Expand Down
18 changes: 18 additions & 0 deletions test/SourceKit/CursorInfo/cursor_generics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ func someFunc <A>() -> A {
fatalError()
}

// rdar://problem/36871908
class MyType<T> {
let test: Bool = false
let items: [Int] = []
func myMethod() {
if test {}
for i in items {}
}
}

// RUN: %sourcekitd-test -req=cursor -pos=1:10 %s -- %s | %FileCheck -check-prefix=CHECK1 %s
// CHECK1: <Declaration>func testGenerics&lt;T&gt;(x: <Type usr="s:15cursor_generics12testGenericsyx1x_tlF1TL_xmfp">T</Type>)</Declaration>

Expand All @@ -19,3 +29,11 @@ func someFunc <A>() -> A {
// RUN: %sourcekitd-test -req=cursor -pos=8:16 %s -- %s | %FileCheck -check-prefix=CHECK3 %s
// CHECK3: source.lang.swift.decl.generic_type_param
// CHECK3: <Declaration>A</Declaration>

// RUN: %sourcekitd-test -req=cursor -pos=17:8 %s -- %s | %FileCheck -check-prefix=CHECK4 %s
// CHECK4: source.lang.swift.ref.var.instance
// CHECK4: <Declaration>let test: <Type usr="s:Sb">Bool</Type></Declaration>

// RUN: %sourcekitd-test -req=cursor -pos=18:14 %s -- %s | %FileCheck -check-prefix=CHECK5 %s
// CHECK5: source.lang.swift.ref.var.instance
// CHECK5: <Declaration>let items: [<Type usr="s:Si">Int</Type>]</Declaration>