Skip to content

Commit d1f6b3e

Browse files
hborlaxedin
authored andcommitted
[Diagnostics] When diagnosing an ambiguous overload, don't mention "call"
if the expression is not a function application.
1 parent 1a628f3 commit d1f6b3e

File tree

6 files changed

+13
-9
lines changed

6 files changed

+13
-9
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +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 %select{%2|}1",
65-
(DescriptiveDeclKind, bool, DeclBaseName))
66-
ERROR(no_overloads_match_exactly_in_assignment,none,
67-
"no exact matches in assignment to %0",
68-
(DeclBaseName))
64+
"no exact matches in %select{reference|call}0 to %1 %select{%3|}2",
65+
(bool, DescriptiveDeclKind, bool, DeclBaseName))
6966

7067
NOTE(candidate_partial_match,none,
7168
"candidate has partially matching parameter list %0",

lib/Sema/ConstraintSystem.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2807,6 +2807,8 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
28072807
DiagnosticTransaction transaction(getASTContext().Diags);
28082808

28092809
auto *commonAnchor = commonCalleeLocator->getAnchor();
2810+
if (auto *callExpr = dyn_cast<CallExpr>(commonAnchor))
2811+
commonAnchor = callExpr->getDirectCallee();
28102812
auto &DE = getASTContext().Diags;
28112813
auto name = decl->getFullName();
28122814

@@ -2825,8 +2827,13 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
28252827
DE.diagnose(commonAnchor->getLoc(), diag::no_candidates_match_result_type,
28262828
baseName.userFacingName(), getContextualType(anchor));
28272829
} else {
2830+
bool isApplication = llvm::find_if(ArgumentInfos, [&](const auto argInfo) {
2831+
return argInfo.first->getAnchor() == commonAnchor;
2832+
}) != ArgumentInfos.end();
2833+
28282834
DE.diagnose(commonAnchor->getLoc(),
28292835
diag::no_overloads_match_exactly_in_call,
2836+
isApplication,
28302837
decl->getDescriptiveKind(), name.isSpecial(),
28312838
name.getBaseName());
28322839
}

test/Constraints/diagnostics.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ class CacheValue {
935935

936936
func valueForKey<K>(_ key: K) -> CacheValue? {
937937
let cache = NSCache<K, CacheValue>()
938-
return cache.object(forKey: key)?.value // expected-error {{no exact matches in call to instance method 'value'}}
938+
return cache.object(forKey: key)?.value // expected-error {{no exact matches in reference to instance method 'value'}}
939939
}
940940

941941
// SR-2242: poor diagnostic when argument label is omitted

test/Constraints/patterns.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ switch staticMembers {
301301
// TODO: repeated error message
302302
case .optProp: break // expected-error* {{not unwrapped}}
303303

304-
case .method: break // expected-error{{no exact matches in call to static method 'method'}}
304+
case .method: break // expected-error{{no exact matches in reference to static method 'method'}}
305305
case .method(0): break
306306
case .method(_): break // expected-error{{'_' can only appear in a pattern}}
307307
case .method(let x): break // expected-error{{cannot appear in an expression}}

test/NameBinding/import-resolution-overload.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ scopedFunction = 42
4646
// FIXME: Should be an error -- a type name and a function cannot overload.
4747
var _ : Int = TypeNameWins(42)
4848

49-
TypeNameWins = 42 // expected-error {{no exact matches in assignment to 'TypeNameWins'}}
49+
TypeNameWins = 42 // expected-error {{no exact matches in reference to global function 'TypeNameWins'}}
5050
var _ : TypeNameWins // no-warning
5151

5252
// rdar://problem/21739333

test/Parse/super.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class D : B {
3939
super.bar // expected-error {{expression resolves to an unused function}}
4040
super.bar()
4141
// FIXME: should also say "'super.init' cannot be referenced outside of an initializer"
42-
super.init // expected-error{{no exact matches in call to initializer}}
42+
super.init // expected-error{{no exact matches in reference to initializer}}
4343
super.init() // expected-error{{'super.init' cannot be called outside of an initializer}}
4444
super.init(0) // expected-error{{'super.init' cannot be called outside of an initializer}} // expected-error {{missing argument label 'x:' in call}}
4545
super[0] // expected-error {{expression resolves to an unused subscript}}

0 commit comments

Comments
 (0)