Skip to content

Commit 1a628f3

Browse files
hborlaxedin
authored andcommitted
[Diagnostics] Simplify logic in diagnoseAmbiguityWithFixes for emitting
the ambiguity diagnostic by combining a few special errors into one.
1 parent 651c27b commit 1a628f3

File tree

4 files changed

+8
-28
lines changed

4 files changed

+8
-28
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,14 +61,8 @@ ERROR(ambiguous_member_overload_set,none,
6161
ERROR(ambiguous_reference_to_decl,none,
6262
"ambiguous reference to %0 %1", (DescriptiveDeclKind, DeclName))
6363
ERROR(no_overloads_match_exactly_in_call,none,
64-
"no exact matches in call to %0 %1",
65-
(DescriptiveDeclKind, DeclName))
66-
ERROR(no_overloads_match_exactly_in_call_no_labels,none,
67-
"no exact matches in call to %0 %1",
68-
(DescriptiveDeclKind, DeclBaseName))
69-
ERROR(no_overloads_match_exactly_in_call_special,none,
70-
"no exact matches in call to %0",
71-
(DescriptiveDeclKind))
64+
"no exact matches in call to %0 %select{%2|}1",
65+
(DescriptiveDeclKind, bool, DeclBaseName))
7266
ERROR(no_overloads_match_exactly_in_assignment,none,
7367
"no exact matches in assignment to %0",
7468
(DeclBaseName))

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2824,25 +2824,11 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
28242824
auto baseName = name.getBaseName();
28252825
DE.diagnose(commonAnchor->getLoc(), diag::no_candidates_match_result_type,
28262826
baseName.userFacingName(), getContextualType(anchor));
2827-
} else if (name.isSpecial()) {
2828-
// If this is a special name, avoid printing it because printing the
2829-
// decl kind is sufficient.
2830-
DE.diagnose(commonAnchor->getLoc(),
2831-
diag::no_overloads_match_exactly_in_call_special,
2832-
decl->getDescriptiveKind());
2833-
} else if (llvm::all_of(ambiguousOverload->choices,
2834-
[&name](const OverloadChoice &choice) {
2835-
return choice.getDecl()->getFullName() == name;
2836-
})) {
2837-
// If the labels match in each overload, print a full name.
2838-
DE.diagnose(commonAnchor->getLoc(),
2839-
diag::no_overloads_match_exactly_in_call,
2840-
decl->getDescriptiveKind(), name);
28412827
} else {
2842-
// If the labels are different, we can only print a base name.
28432828
DE.diagnose(commonAnchor->getLoc(),
2844-
diag::no_overloads_match_exactly_in_call_no_labels,
2845-
decl->getDescriptiveKind(), name.getBaseName());
2829+
diag::no_overloads_match_exactly_in_call,
2830+
decl->getDescriptiveKind(), name.isSpecial(),
2831+
name.getBaseName());
28462832
}
28472833

28482834
// Produce candidate notes

test/Sema/diag_non_ephemeral.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ func takesPointerOverload(x: Int = 0, @_nonEphemeral _ ptr: UnsafeMutablePointer
489489

490490
func testAmbiguity() {
491491
var arr = [1, 2, 3]
492-
takesPointerOverload(&arr) // expected-error {{no exact matches in call to global function 'takesPointerOverload(x:_:)'}}
492+
takesPointerOverload(&arr) // expected-error {{no exact matches in call to global function 'takesPointerOverload'}}
493493
}
494494

495495
func takesPointerOverload2(@_nonEphemeral _ ptr: UnsafePointer<Int>) {}

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)