Skip to content

[4.1][CursorInfo] Fix crash on init call of inner class with outer generic context #14162

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
13 changes: 13 additions & 0 deletions test/SourceKit/CursorInfo/rdar_35819975.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Checks that we don't crash
// RUN: %sourcekitd-test -req=cursor -pos=10:5 %s -- %s | %FileCheck %s
// RUN: %sourcekitd-test -req=cursor -pos=11:11 %s -- %s | %FileCheck --check-prefix=CHECK2 %s
// CHECK: source.lang.swift.ref.class
// CHECK2: source.lang.swift.ref.function.constructor

class Bar<T> {
class Inner {}
func foo() {
Inner()
Inner.init()
}
}
19 changes: 12 additions & 7 deletions tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -694,7 +694,6 @@ getParamParentNameOffset(const ValueDecl *VD, SourceLoc Cursor) {
static bool passCursorInfoForDecl(SourceFile* SF,
const ValueDecl *VD,
const ModuleDecl *MainModule,
const Type Ty,
const Type ContainerTy,
bool IsRef,
bool RetrieveRefactoring,
Expand All @@ -710,7 +709,7 @@ static bool passCursorInfoForDecl(SourceFile* SF,
return true;

SmallString<64> SS;
auto BaseType = findBaseTypeForReplacingArchetype(VD, Ty);
auto BaseType = findBaseTypeForReplacingArchetype(VD, ContainerTy);
bool InSynthesizedExtension = false;
if (BaseType) {
if (auto Target = BaseType->getAnyNominal()) {
Expand Down Expand Up @@ -1293,11 +1292,17 @@ static void resolveCursor(SwiftLangSupport &Lang,
CompInvok, Receiver);
return;
case CursorInfoKind::ValueRef: {
ValueDecl *VD = CursorInfo.CtorTyRef ? CursorInfo.CtorTyRef : CursorInfo.ValueD;
ValueDecl *VD = CursorInfo.ValueD;
Type ContainerType = CursorInfo.ContainerType;
if (CursorInfo.CtorTyRef) {
// Treat constructor calls, e.g. MyType(), as the type itself,
// rather than its constructor.
VD = CursorInfo.CtorTyRef;
ContainerType = Type();
}
bool Failed = passCursorInfoForDecl(&AstUnit->getPrimarySourceFile(),
VD, MainModule,
CursorInfo.ContainerType,
CursorInfo.ContainerType,
ContainerType,
CursorInfo.IsRef,
Actionables,
CursorInfo,
Expand Down Expand Up @@ -1589,7 +1594,7 @@ void SwiftLangSupport::getCursorInfo(
// FIXME: Should pass the main module for the interface but currently
// it's not necessary.
passCursorInfoForDecl(
/*SourceFile*/nullptr, Entity.Dcl, /*MainModule*/ nullptr, Type(),
/*SourceFile*/nullptr, Entity.Dcl, /*MainModule*/ nullptr,
Type(), Entity.IsRef, Actionables, ResolvedCursorInfo(),
/*OrigBufferID=*/None, SourceLoc(),
{}, *this, Invok, {}, Receiver);
Expand Down Expand Up @@ -1780,7 +1785,7 @@ resolveCursorFromUSR(SwiftLangSupport &Lang, StringRef InputFile, StringRef USR,
}
bool Failed =
passCursorInfoForDecl(/*SourceFile*/nullptr, VD, MainModule, selfTy,
Type(), /*IsRef=*/false, false, ResolvedCursorInfo(),
/*IsRef=*/false, false, ResolvedCursorInfo(),
BufferID, SourceLoc(), {}, Lang, CompInvok,
PreviousASTSnaps, Receiver);
if (Failed) {
Expand Down