mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Refactoring] Only rename variables in capture lists once
Inside capture lists like `{ [test] in }`, `test` refers to both the newly declared, captured variable and the referenced variable it is initialized from. We currently try to rename it twice, yielding invalid, confusing results. Make sure to only record this situation once.
Fixes rdar://78522816 [SR-14661]
This commit is contained in:
@@ -654,7 +654,22 @@ private:
|
||||
Action startSourceEntity(const IndexSymbol &symbol) override {
|
||||
if (symbol.USR == USR) {
|
||||
if (auto loc = indexSymbolToRenameLoc(symbol, newName)) {
|
||||
locations.push_back(std::move(*loc));
|
||||
// Inside capture lists like `{ [test] in }`, 'test' refers to both the
|
||||
// newly declared, captured variable and the referenced variable it is
|
||||
// initialized from. Make sure to only rename it once.
|
||||
auto existingLoc = llvm::find_if(locations, [&](RenameLoc searchLoc) {
|
||||
return searchLoc.Line == loc->Line && searchLoc.Column == loc->Column;
|
||||
});
|
||||
if (existingLoc == locations.end()) {
|
||||
locations.push_back(std::move(*loc));
|
||||
} else {
|
||||
assert(existingLoc->OldName == loc->OldName &&
|
||||
existingLoc->NewName == loc->NewName &&
|
||||
existingLoc->IsFunctionLike == loc->IsFunctionLike &&
|
||||
existingLoc->IsNonProtocolType ==
|
||||
existingLoc->IsNonProtocolType &&
|
||||
"Asked to do a different rename for the same location?");
|
||||
}
|
||||
}
|
||||
}
|
||||
return IndexDataConsumer::Continue;
|
||||
|
||||
Reference in New Issue
Block a user