[clangd] Fix an assertion violation in rename.

NamedDecl::getName() asserts the name must be an identifier.

Differential Revision: https://reviews.llvm.org/D92642
This commit is contained in:
Haojian Wu 2020-12-04 12:23:26 +01:00
parent df1ddc4234
commit 445289aa63
2 changed files with 11 additions and 1 deletions

View File

@ -637,7 +637,10 @@ llvm::Expected<RenameResult> rename(const RenameInputs &RInputs) {
if (DeclsUnderCursor.size() > 1)
return makeError(ReasonToReject::AmbiguousSymbol);
const auto &RenameDecl = **DeclsUnderCursor.begin();
if (RenameDecl.getName() == RInputs.NewName)
const auto *ID = RenameDecl.getIdentifier();
if (!ID)
return makeError(ReasonToReject::UnsupportedSymbol);
if (ID->getName() == RInputs.NewName)
return makeError(ReasonToReject::SameName);
auto Invalid = checkName(RenameDecl, RInputs.NewName);
if (Invalid)

View File

@ -946,6 +946,13 @@ TEST(RenameTest, Renameable) {
)cpp",
"not a supported kind", !HeaderFile, Index},
{R"cpp(// disallow rename on non-normal identifiers.
@interface Foo {}
-(int) fo^o:(int)x; // Token is an identifier, but declaration name isn't a simple identifier.
@end
)cpp",
"not a supported kind", HeaderFile, Index},
{R"cpp(
void foo(int);
void foo(char);