Skip to content

[RelatedIdents] Fix an assertion failure if two invalid declarations have the same base name #73468

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
1 change: 1 addition & 0 deletions include/swift/Index/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ namespace index {
void indexDeclContext(DeclContext *DC, IndexDataConsumer &consumer);
void indexSourceFile(SourceFile *SF, IndexDataConsumer &consumer);
void indexModule(ModuleDecl *module, IndexDataConsumer &consumer);
bool printDisplayName(const swift::ValueDecl *D, llvm::raw_ostream &OS);

} // end namespace index
} // end namespace swift
Expand Down
2 changes: 1 addition & 1 deletion lib/Index/Index.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ printArtificialName(const swift::AbstractStorageDecl *ASD, AccessorKind AK, llvm
llvm_unreachable("Unhandled AccessorKind in switch.");
}

static bool printDisplayName(const swift::ValueDecl *D, llvm::raw_ostream &OS) {
bool index::printDisplayName(const swift::ValueDecl *D, llvm::raw_ostream &OS) {
if (!D->hasName() && !isa<ParamDecl>(D)) {
auto *FD = dyn_cast<AccessorDecl>(D);
if (!FD)
Expand Down
16 changes: 4 additions & 12 deletions lib/Refactoring/LocalRename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,13 @@ swift::ide::getRenameInfo(ResolvedCursorInfoPtr cursorInfo) {
}

class RenameRangeCollector : public IndexDataConsumer {
StringRef usr;
const ValueDecl *declToRename;
std::unique_ptr<StringScratchSpace> stringStorage;
std::vector<RenameLoc> locations;

public:
RenameRangeCollector(StringRef usr)
: usr(usr), stringStorage(new StringScratchSpace()) {}

RenameRangeCollector(const ValueDecl *D)
: stringStorage(new StringScratchSpace()) {
SmallString<64> SS;
llvm::raw_svector_ostream OS(SS);
printValueDeclUSR(D, OS);
usr = stringStorage->copyString(SS.str());
}
RenameRangeCollector(const ValueDecl *declToRename)
: declToRename(declToRename), stringStorage(new StringScratchSpace()) {}

RenameRangeCollector(RenameRangeCollector &&collector) = default;

Expand All @@ -228,7 +220,7 @@ class RenameRangeCollector : public IndexDataConsumer {
bool finishDependency(bool isClangModule) override { return true; }

Action startSourceEntity(const IndexSymbol &symbol) override {
if (symbol.USR != usr) {
if (symbol.decl != declToRename) {
return IndexDataConsumer::Continue;
}
auto loc = indexSymbolToRenameLoc(symbol);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
struct Foo {
func bar(body: Invalid) {}

// RUN: %sourcekitd-test -req=related-idents -pos=%(line + 1):8 %s -- %s
func bar(ignoreCase: Bool, body: Invalid) {}
}