Skip to content

Commit

Permalink
allow any ValueDecl to take part in picking a best candidate (swiftla…
Browse files Browse the repository at this point in the history
…ng#65441)

rdar://105099207
  • Loading branch information
QuietMisdreavus committed Apr 27, 2023
1 parent 2984f0a commit 07fc40c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 10 additions & 4 deletions lib/SymbolGraphGen/SymbolGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,15 +276,21 @@ void SymbolGraph::recordMemberRelationship(Symbol S) {

bool SymbolGraph::synthesizedMemberIsBestCandidate(const ValueDecl *VD,
const NominalTypeDecl *Owner) const {
const auto *FD = dyn_cast<FuncDecl>(VD);
if (!FD) {
DeclName Name;
if (const auto *FD = dyn_cast<FuncDecl>(VD)) {
Name = FD->getEffectiveFullName();
} else {
Name = VD->getName();
}

if (!Name) {
return true;
}

auto *DC = const_cast<DeclContext*>(Owner->getDeclContext());

ResolvedMemberResult Result =
resolveValueMember(*DC, Owner->getSelfTypeInContext(),
FD->getEffectiveFullName());
resolveValueMember(*DC, Owner->getSelfTypeInContext(), Name);

const auto ViableCandidates =
Result.getMemberDecls(InterestedMemberKind::All);
Expand Down
18 changes: 15 additions & 3 deletions test/SymbolGraph/Relationships/Synthesized/PickBestCandidate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,36 @@
public protocol P {
func foo()
func bar()

var baz: Int { get }
var qux: Int { get }
}

public protocol Q : P {}
extension Q {
public func foo() {}
public func bar() {}

public var baz: Int { 0 }
public var qux: Int { 0 }
}

public protocol R : Q {}
extension R {
public func foo() {}
public func bar() {}

public var baz: Int { 1 }
public var qux: Int { 1 }
}

public struct MyStruct: R {
public func bar() {}

public var qux: Int { 2 }
}

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

0 comments on commit 07fc40c

Please sign in to comment.