Skip to content

Commit 783add0

Browse files
committed
[CSDiagnostics] Split no exact match diagnostic into three choices
1. If this is a special name avoid printing it because printing kind is sufficient; 2. If all of the labels match, print a full name; 3. If labels in different choices are different, it means that we can only print a base name.
1 parent caf266f commit 783add0

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ ERROR(ambiguous_member_overload_set,none,
5757
ERROR(ambiguous_reference_to_decl,none,
5858
"ambiguous reference to %0 %1", (DescriptiveDeclKind, DeclName))
5959
ERROR(no_overloads_match_exactly_in_call,none,
60+
"no exact matches in call to %0 %1",
61+
(DescriptiveDeclKind, DeclName))
62+
ERROR(no_overloads_match_exactly_in_call_no_labels,none,
6063
"no exact matches in call to %0 %1",
6164
(DescriptiveDeclKind, DeclBaseName))
6265
ERROR(no_overloads_match_exactly_in_call_special,none,

lib/Sema/ConstraintSystem.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,15 +2490,28 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
24902490
diag::could_not_find_subscript_member_did_you_mean,
24912491
getType(UDE->getBase()));
24922492
} else {
2493-
auto name = decl->getBaseName();
2493+
auto name = decl->getFullName();
2494+
// Three choices here:
2495+
// 1. If this is a special name avoid printing it because
2496+
// printing kind is sufficient;
2497+
// 2. If all of the labels match, print a full name;
2498+
// 3. If labels in different choices are different, it means
2499+
// that we can only print a base name.
24942500
if (name.isSpecial()) {
24952501
TC.diagnose(commonAnchor->getLoc(),
24962502
diag::no_overloads_match_exactly_in_call_special,
24972503
decl->getDescriptiveKind());
2498-
} else {
2504+
} else if (llvm::all_of(distinctChoices,
2505+
[&name](const ValueDecl *choice) {
2506+
return choice->getFullName() == name;
2507+
})) {
24992508
TC.diagnose(commonAnchor->getLoc(),
25002509
diag::no_overloads_match_exactly_in_call,
25012510
decl->getDescriptiveKind(), name);
2511+
} else {
2512+
TC.diagnose(commonAnchor->getLoc(),
2513+
diag::no_overloads_match_exactly_in_call_no_labels,
2514+
decl->getDescriptiveKind(), name.getBaseName());
25022515
}
25032516
}
25042517

test/decl/ext/protocol.swift

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

238238
func testP4(_ s4a: S4a, s4b: S4b, s4c: S4c, s4d: S4d) {
239-
s4a.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a'}}
239+
s4a.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a()'}}
240240
s4b.extP4a() // ok
241-
s4c.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a'}}
241+
s4c.extP4a() // expected-error{{no exact matches in call to instance method 'extP4a()'}}
242242
s4c.extP4Int() // okay
243243
var b1 = s4d.extP4a() // okay, "Bool" version
244244
b1 = true // checks type above

0 commit comments

Comments
 (0)