Skip to content

Commit 07fc40c

Browse files
allow any ValueDecl to take part in picking a best candidate (#65441)
rdar://105099207
1 parent 2984f0a commit 07fc40c

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lib/SymbolGraphGen/SymbolGraph.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,21 @@ void SymbolGraph::recordMemberRelationship(Symbol S) {
276276

277277
bool SymbolGraph::synthesizedMemberIsBestCandidate(const ValueDecl *VD,
278278
const NominalTypeDecl *Owner) const {
279-
const auto *FD = dyn_cast<FuncDecl>(VD);
280-
if (!FD) {
279+
DeclName Name;
280+
if (const auto *FD = dyn_cast<FuncDecl>(VD)) {
281+
Name = FD->getEffectiveFullName();
282+
} else {
283+
Name = VD->getName();
284+
}
285+
286+
if (!Name) {
281287
return true;
282288
}
289+
283290
auto *DC = const_cast<DeclContext*>(Owner->getDeclContext());
284291

285292
ResolvedMemberResult Result =
286-
resolveValueMember(*DC, Owner->getSelfTypeInContext(),
287-
FD->getEffectiveFullName());
293+
resolveValueMember(*DC, Owner->getSelfTypeInContext(), Name);
288294

289295
const auto ViableCandidates =
290296
Result.getMemberDecls(InterestedMemberKind::All);

test/SymbolGraph/Relationships/Synthesized/PickBestCandidate.swift

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,36 @@
66
public protocol P {
77
func foo()
88
func bar()
9+
10+
var baz: Int { get }
11+
var qux: Int { get }
912
}
1013

1114
public protocol Q : P {}
1215
extension Q {
1316
public func foo() {}
1417
public func bar() {}
18+
19+
public var baz: Int { 0 }
20+
public var qux: Int { 0 }
1521
}
1622

1723
public protocol R : Q {}
1824
extension R {
1925
public func foo() {}
2026
public func bar() {}
27+
28+
public var baz: Int { 1 }
29+
public var qux: Int { 1 }
2130
}
2231

2332
public struct MyStruct: R {
2433
public func bar() {}
34+
35+
public var qux: Int { 2 }
2536
}
2637

27-
// MyStruct gets one and only one synthesized `foo`.
28-
// MyStruct gets no synthesized `bar`, because it has its own implementation.
29-
// CHECK-COUNT-1: ::SYNTHESIZED::
38+
// MyStruct gets one and only one synthesized `foo` and `baz`.
39+
// MyStruct gets no synthesized `bar` and `qux`, because it has its own implementation.
40+
// CHECK-COUNT-2: "precise": {{.*}}::SYNTHESIZED::
41+
// CHECK-NOT: "precise": {{.*}}::SYNTHESIZED::

0 commit comments

Comments
 (0)