Skip to content

Commit caf266f

Browse files
committed
[CSDiagnostics] Use special error message when call didn't match exactly
For multiple solutions with fixes for the same call, replace `ambiguous reference` diagnostic with the one that explicitly mentions that there are no exact matches, and provide partially matched candidates as notes.
1 parent bd21fb4 commit caf266f

File tree

4 files changed

+20
-10
lines changed

4 files changed

+20
-10
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ ERROR(ambiguous_member_overload_set,none,
5656
"ambiguous reference to member %0", (DeclName))
5757
ERROR(ambiguous_reference_to_decl,none,
5858
"ambiguous reference to %0 %1", (DescriptiveDeclKind, DeclName))
59+
ERROR(no_overloads_match_exactly_in_call,none,
60+
"no exact matches in call to %0 %1",
61+
(DescriptiveDeclKind, DeclBaseName))
62+
ERROR(no_overloads_match_exactly_in_call_special,none,
63+
"no exact matches in call to %0",
64+
(DescriptiveDeclKind))
5965

6066
ERROR(ambiguous_subscript,none,
6167
"ambiguous subscript with base type %0 and index type %1",

lib/Sema/ConstraintSystem.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,8 +2490,16 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
24902490
diag::could_not_find_subscript_member_did_you_mean,
24912491
getType(UDE->getBase()));
24922492
} else {
2493-
TC.diagnose(commonAnchor->getLoc(), diag::ambiguous_reference_to_decl,
2494-
decl->getDescriptiveKind(), decl->getFullName());
2493+
auto name = decl->getBaseName();
2494+
if (name.isSpecial()) {
2495+
TC.diagnose(commonAnchor->getLoc(),
2496+
diag::no_overloads_match_exactly_in_call_special,
2497+
decl->getDescriptiveKind());
2498+
} else {
2499+
TC.diagnose(commonAnchor->getLoc(),
2500+
diag::no_overloads_match_exactly_in_call,
2501+
decl->getDescriptiveKind(), name);
2502+
}
24952503
}
24962504

24972505
for (const auto &viable : viableSolutions) {

test/decl/ext/protocol.swift

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,9 @@ extension P4 where Self.AssocP4 == Bool {
236236
}
237237

238238
func testP4(_ s4a: S4a, s4b: S4b, s4c: S4c, s4d: S4d) {
239-
// FIXME: Both of the 'ambiguous' examples below are indeed ambiguous,
240-
// because they don't match on conformance and same-type
241-
// requirement of different overloads, but diagnostic
242-
// could be improved to point out exactly what is missing in each case.
243-
s4a.extP4a() // expected-error{{ambiguous reference to instance method 'extP4a()'}}
239+
s4a.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a'}}
244240
s4b.extP4a() // ok
245-
s4c.extP4a() // expected-error{{ambiguous reference to instance method 'extP4a()'}}
241+
s4c.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a'}}
246242
s4c.extP4Int() // okay
247243
var b1 = s4d.extP4a() // okay, "Bool" version
248244
b1 = true // checks type above

validation-test/Sema/type_checker_crashers_fixed/rdar45470505.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ extension BinaryInteger {
44
init(bytes: [UInt8]) { fatalError() }
55

66
init<S: Sequence>(bytes: S) where S.Iterator.Element == UInt8 {
7-
self.init(bytes // expected-error {{ambiguous reference to initializer 'init(_:)'}}
8-
// expected-note@-1 {{}}
7+
self.init(bytes // expected-error {{no exact matches in call to initializer}}
8+
// expected-note@-1 {{}}
99

1010
extension
1111
// expected-error@-1 {{declaration is only valid at file scope}}

0 commit comments

Comments
 (0)