Skip to content

Commit 6ff6e3c

Browse files
author
Nathan Hawes
committed
[CursorInfo] Fix crash on init call of inner NTD with generic outer NTD
Resolves rdar://problem/35819975
1 parent 4973417 commit 6ff6e3c

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Checks that we don't crash
2+
// RUN: %sourcekitd-test -req=cursor -pos=10:5 %s -- %s | %FileCheck %s
3+
// RUN: %sourcekitd-test -req=cursor -pos=11:11 %s -- %s | %FileCheck --check-prefix=CHECK2 %s
4+
// CHECK: source.lang.swift.ref.class
5+
// CHECK2: source.lang.swift.ref.function.constructor
6+
7+
class Bar<T> {
8+
class Inner {}
9+
func foo() {
10+
Inner()
11+
Inner.init()
12+
}
13+
}

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,6 @@ getParamParentNameOffset(const ValueDecl *VD, SourceLoc Cursor) {
694694
static bool passCursorInfoForDecl(SourceFile* SF,
695695
const ValueDecl *VD,
696696
const ModuleDecl *MainModule,
697-
const Type Ty,
698697
const Type ContainerTy,
699698
bool IsRef,
700699
bool RetrieveRefactoring,
@@ -710,7 +709,7 @@ static bool passCursorInfoForDecl(SourceFile* SF,
710709
return true;
711710

712711
SmallString<64> SS;
713-
auto BaseType = findBaseTypeForReplacingArchetype(VD, Ty);
712+
auto BaseType = findBaseTypeForReplacingArchetype(VD, ContainerTy);
714713
bool InSynthesizedExtension = false;
715714
if (BaseType) {
716715
if (auto Target = BaseType->getAnyNominal()) {
@@ -1293,11 +1292,17 @@ static void resolveCursor(SwiftLangSupport &Lang,
12931292
CompInvok, Receiver);
12941293
return;
12951294
case CursorInfoKind::ValueRef: {
1296-
ValueDecl *VD = CursorInfo.CtorTyRef ? CursorInfo.CtorTyRef : CursorInfo.ValueD;
1295+
ValueDecl *VD = CursorInfo.ValueD;
1296+
Type ContainerType = CursorInfo.ContainerType;
1297+
if (CursorInfo.CtorTyRef) {
1298+
// Treat constructor calls, e.g. MyType(), as the type itself,
1299+
// rather than its constructor.
1300+
VD = CursorInfo.CtorTyRef;
1301+
ContainerType = Type();
1302+
}
12971303
bool Failed = passCursorInfoForDecl(&AstUnit->getPrimarySourceFile(),
12981304
VD, MainModule,
1299-
CursorInfo.ContainerType,
1300-
CursorInfo.ContainerType,
1305+
ContainerType,
13011306
CursorInfo.IsRef,
13021307
Actionables,
13031308
CursorInfo,
@@ -1589,7 +1594,7 @@ void SwiftLangSupport::getCursorInfo(
15891594
// FIXME: Should pass the main module for the interface but currently
15901595
// it's not necessary.
15911596
passCursorInfoForDecl(
1592-
/*SourceFile*/nullptr, Entity.Dcl, /*MainModule*/ nullptr, Type(),
1597+
/*SourceFile*/nullptr, Entity.Dcl, /*MainModule*/ nullptr,
15931598
Type(), Entity.IsRef, Actionables, ResolvedCursorInfo(),
15941599
/*OrigBufferID=*/None, SourceLoc(),
15951600
{}, *this, Invok, {}, Receiver);
@@ -1780,7 +1785,7 @@ resolveCursorFromUSR(SwiftLangSupport &Lang, StringRef InputFile, StringRef USR,
17801785
}
17811786
bool Failed =
17821787
passCursorInfoForDecl(/*SourceFile*/nullptr, VD, MainModule, selfTy,
1783-
Type(), /*IsRef=*/false, false, ResolvedCursorInfo(),
1788+
/*IsRef=*/false, false, ResolvedCursorInfo(),
17841789
BufferID, SourceLoc(), {}, Lang, CompInvok,
17851790
PreviousASTSnaps, Receiver);
17861791
if (Failed) {

0 commit comments

Comments
 (0)