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

For example:
class Foo<T> {
  let test: Bool = false
  let items: [Int] = []
  func foo() {
    if test {} // crashes on test
    for i in items {} // crashes on items
  }
}

We were picking up the incorrect containing type (Bool rather than Foo<T>).
Resolves rdar://problem/36871908.
This commit is contained in:
Nathan Hawes
2018-01-25 14:51:08 -08:00
parent 501a176a26
commit 80e10b188b
2 changed files with 20 additions and 2 deletions

View File

@@ -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();
}
}