Skip to content

Commit 3682d8e

Browse files
authored
Merge pull request #71227 from ahoppen/ahoppen/related-idents-self
[SourceKit] Fix a crash when performing related identiifers request on `self`
2 parents d3cd72f + f0ea24d commit 3682d8e

File tree

4 files changed

+18
-4
lines changed

4 files changed

+18
-4
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
struct Test {
2+
func foo() {
3+
// RUN: %sourcekitd-test -req=related-idents -pos=%(line + 1):6 %s -- %s | %FileCheck %s
4+
self
5+
}
6+
}
7+
8+
// CHECK: START RANGES
9+
// CHECK-NEXT: END RANGES

tools/SourceKit/include/SourceKit/Core/LangSupport.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,10 +792,10 @@ struct RelatedIdentInfo {
792792
/// Result of `findRelatedIdentifiersInFile`.
793793
struct RelatedIdentsResult {
794794
SmallVector<RelatedIdentInfo, 8> RelatedIdents;
795-
std::string OldName;
795+
std::optional<std::string> OldName;
796796

797797
RelatedIdentsResult(SmallVector<RelatedIdentInfo, 8> RelatedIdents,
798-
std::string OldName)
798+
std::optional<std::string> OldName)
799799
: RelatedIdents(RelatedIdents), OldName(OldName) {}
800800

801801
static RelatedIdentsResult empty() { return RelatedIdentsResult({}, ""); }

tools/SourceKit/lib/SwiftLang/SwiftSourceDocInfo.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2550,7 +2550,10 @@ void SwiftLangSupport::findRelatedIdentifiersInFile(
25502550

25512551
RenameLocs Locs = localRenameLocs(SrcFile, Info->VD);
25522552

2553-
std::string OldName = Locs.getLocations().front().OldName.str();
2553+
std::optional<std::string> OldName;
2554+
if (!Locs.getLocations().empty()) {
2555+
OldName = Locs.getLocations().front().OldName.str();
2556+
}
25542557
#ifndef NDEBUG
25552558
for (auto loc : Locs.getLocations()) {
25562559
assert(loc.OldName == OldName &&

tools/SourceKit/tools/sourcekitd/lib/Service/Requests.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2903,7 +2903,9 @@ static void findRelatedIdents(StringRef PrimaryFilePath,
29032903
Elem.set(KeyLength, R.Length);
29042904
Elem.set(KeyNameType, renameLocUsageUID(R.Usage));
29052905
}
2906-
RespBuilder.getDictionary().set(KeyName, Info.OldName);
2906+
if (Info.OldName) {
2907+
RespBuilder.getDictionary().set(KeyName, *Info.OldName);
2908+
}
29072909

29082910
Rec(RespBuilder.createResponse());
29092911
});

0 commit comments

Comments
 (0)