Skip to content

Commit a14e329

Browse files
committed
Say "ambiguous use of 'foo'" instead of "'foo(bar:)'".
...unless the argument labels are the same for every possible overload. Only affects diagnostics.
1 parent 5746671 commit a14e329

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,12 +312,26 @@ static unsigned countDistinctOverloads(ArrayRef<OverloadChoice> choices) {
312312

313313
/// \brief Determine the name of the overload in a set of overload choices.
314314
static DeclName getOverloadChoiceName(ArrayRef<OverloadChoice> choices) {
315+
DeclName name;
315316
for (auto choice : choices) {
316-
if (choice.isDecl())
317-
return choice.getDecl()->getFullName();
317+
if (!choice.isDecl())
318+
continue;
319+
320+
DeclName nextName = choice.getDecl()->getFullName();
321+
if (!name) {
322+
name = nextName;
323+
continue;
324+
}
325+
326+
if (name != nextName) {
327+
// Assume all choices have the same base name and only differ in
328+
// argument labels. This may not be a great assumption, but we don't
329+
// really have a way to recover for diagnostics otherwise.
330+
return name.getBaseName();
331+
}
318332
}
319333

320-
return DeclName();
334+
return name;
321335
}
322336

323337
static bool diagnoseAmbiguity(ConstraintSystem &cs,

test/expr/unary/selector/selector.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ class C1 {
1515
@objc class func method3(_ a: A, b: B) { } // expected-note{{found this candidate}}
1616
@objc class func method3(a: A, b: B) { } // expected-note{{found this candidate}}
1717

18+
@objc(ambiguous1:b:) class func ambiguous(a: A, b: A) { } // expected-note{{found this candidate}}
19+
@objc(ambiguous2:b:) class func ambiguous(a: A, b: B) { } // expected-note{{found this candidate}}
20+
1821
@objc func getC1() -> AnyObject { return self }
1922

2023
@objc func testUnqualifiedSelector(_ a: A, b: B) {
@@ -83,7 +86,8 @@ func testSelector(_ c1: C1, p1: P1, obj: AnyObject) {
8386
}
8487

8588
func testAmbiguity() {
86-
_ = #selector(C1.method3) // expected-error{{ambiguous use of 'method3(_:b:)'}}
89+
_ = #selector(C1.method3) // expected-error{{ambiguous use of 'method3'}}
90+
_ = #selector(C1.ambiguous) // expected-error{{ambiguous use of 'ambiguous(a:b:)'}}
8791
}
8892

8993
func testUnusedSelector() {

0 commit comments

Comments
 (0)