Skip to content

Fix indexing crash on typealiases across files #65545

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

Closed
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
21 changes: 19 additions & 2 deletions lib/Index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,8 +880,9 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
}
} else if (auto *TAD = dyn_cast<TypeAliasDecl>(D)) {
TypeLoc TL(TAD->getUnderlyingTypeRepr(), TAD->getUnderlyingType());
if (!reportRelatedTypeRef(TL, (SymbolRoleSet)SymbolRole::Reference, D, /*isImplicit=*/true, Loc))
return false;
if (CurrentBufferContainsLoc(TL.getLoc()))
if (!reportRelatedTypeRef(TL, (SymbolRoleSet)SymbolRole::Reference, D, /*isImplicit=*/true, Loc))
return false;
}

return true;
Expand Down Expand Up @@ -1019,6 +1020,22 @@ class IndexSwiftASTWalker : public SourceEntityWalker {

bool indexComment(const Decl *D);

bool CurrentBufferContainsLoc(SourceLoc Loc) {
if (Loc.isInvalid())
return false;

bool inGeneratedBuffer =
!SrcMgr.rangeContainsTokenLoc(SrcMgr.getRangeForBuffer(BufferID), Loc);
if (inGeneratedBuffer) {
unsigned bufferID = CurrentModule->getOriginalLocation(Loc).first;
if (BufferID != bufferID) {
return false;
}
}

return true;
}

// Return the line and column of \p loc, as well as whether it was from a
// generated buffer or not. 0:0 if indexing a module and \p loc is invalid.
// \c None if \p loc is otherwise invalid or its original location isn't
Expand Down
12 changes: 12 additions & 0 deletions test/Index/multifile.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %empty-directory(%t)
// RUN: split-file %s %t

// RUN: %target-swift-frontend -index-store-path %t/idx -o %t/file.o -typecheck -primary-file %t/file2.swift %t/file1.swift -verify

//--- file1.swift

typealias Bar = [Int]

//--- file2.swift

func foo() -> Bar { [] }