Skip to content

Commit 58ffca8

Browse files
committed
[ConstraintSystem] Don't produce partially matching note if none of the overloads matched
1 parent 5f8e3eb commit 58ffca8

File tree

8 files changed

+26
-11
lines changed

8 files changed

+26
-11
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4338,9 +4338,28 @@ static void diagnoseOperatorAmbiguity(ConstraintSystem &cs,
43384338
if (overloadType->hasTypeVariable())
43394339
continue;
43404340

4341-
if (auto *fnType = overloadType->getAs<FunctionType>())
4342-
parameters.insert(
4343-
FunctionType::getParamListAsString(fnType->getParams()));
4341+
auto overloadFnTy = overloadType->getAs<FunctionType>();
4342+
if (!overloadFnTy)
4343+
continue;
4344+
4345+
// If arguments to all parameters have been fixed then there is nothing
4346+
// to note about in this overload.
4347+
std::set<unsigned> fixedParams;
4348+
llvm::for_each(solution.Fixes, [&](const ConstraintFix *fix) {
4349+
auto *locator = fix->getLocator();
4350+
if (getAsExpr(locator->getAnchor()) != applyExpr)
4351+
return;
4352+
4353+
if (auto argLoc = locator->findLast<LocatorPathElt::ApplyArgToParam>()) {
4354+
fixedParams.insert(argLoc->getParamIdx());
4355+
}
4356+
});
4357+
4358+
if (fixedParams.size() == overloadFnTy->getNumParams())
4359+
continue;
4360+
4361+
parameters.insert(
4362+
FunctionType::getParamListAsString(overloadFnTy->getParams()));
43444363
}
43454364

43464365
// All of the overload choices had generic parameters like `Self`.

test/Constraints/bridging.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ func rdar19831698() {
275275
var v71 = true + 1.0 // expected-error{{binary operator '+' cannot be applied to operands of type 'Bool' and 'Double'}}
276276
// expected-note@-1{{overloads for '+'}}
277277
var v72 = true + true // expected-error{{binary operator '+' cannot be applied to two 'Bool' operands}}
278-
// expected-note@-1{{overloads for '+'}}
279278
var v73 = true + [] // expected-error@:13 {{cannot convert value of type 'Bool' to expected argument type 'Array<Bool>'}}
280279
var v75 = true + "str" // expected-error@:13 {{cannot convert value of type 'Bool' to expected argument type 'String'}}
281280
}

test/Constraints/fixes.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,5 +363,4 @@ func testKeyPathSubscriptArgFixes(_ fn: @escaping () -> Int) {
363363
// https://github.com/apple/swift/issues/54865
364364
func f_54865(a: Any, _ str: String?) {
365365
a == str // expected-error {{binary operator '==' cannot be applied to operands of type 'Any' and 'String?'}}
366-
// expected-note@-1 {{overloads for '==' exist with these partially matching parameter lists: (String, String)}}
367366
}

test/Constraints/generics.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,7 @@ func test_requirement_failures_in_ambiguous_context() {
10171017
func f1<T: Equatable>(_: T, _: T) {} // expected-note {{where 'T' = 'A'}}
10181018

10191019
f1(A(), B()) // expected-error {{local function 'f1' requires that 'A' conform to 'Equatable'}}
1020+
// expected-error@-1 {{cannot convert value of type 'B' to expected argument type 'A'}}
10201021

10211022
func f2<T: P_56173, U: P_56173>(_: T, _: U) {}
10221023
// expected-note@-1 {{candidate requires that 'B' conform to 'P_56173' (requirement specified as 'U' : 'P_56173')}}

test/Constraints/operator.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ func rdar46459603() {
219219
var arr = ["key": e]
220220

221221
_ = arr.values == [e]
222-
// expected-error@-1 {{binary operator '==' cannot be applied to operands of type 'Dictionary<String, E>.Values' and '[E]'}}
222+
// expected-error@-1 {{referencing operator function '==' on 'Equatable' requires that 'Dictionary<String, E>.Values' conform to 'Equatable'}}
223+
// expected-error@-2 {{cannot convert value of type '[E]' to expected argument type 'Dictionary<String, E>.Values'}}
224+
223225
_ = [arr.values] == [[e]]
224226
// expected-error@-1 {{referencing operator function '==' on 'Array' requires that 'E' conform to 'Equatable'}} expected-note@-1 {{binary operator '==' cannot be synthesized for enums with associated values}}
225227
// expected-error@-2 {{cannot convert value of type 'Dictionary<String, E>.Values' to expected element type '[E]'}}

test/Constraints/optional.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ func test_force_unwrap_not_being_too_eager() {
436436
func invalidOptionalChaining(a: Any) {
437437
a == "="? // expected-error {{cannot use optional chaining on non-optional value of type 'String'}}
438438
// expected-error@-1 {{binary operator '==' cannot be applied to operands of type 'Any' and 'String?'}}
439-
// expected-note@-2 {{overloads for '==' exist}}
440439
}
441440

442441
/// https://github.com/apple/swift/issues/54739

test/StringProcessing/Parse/forward-slash-regex.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ _ = /x/.../y/
131131

132132
_ = /x/...
133133
// expected-error@-1 {{unary operator '...' cannot be applied to an operand of type 'Regex<Substring>'}}
134-
// expected-note@-2 {{overloads for '...' exist with these partially matching parameter lists}}
135134

136135
do {
137136
_ = /x /...

test/stdlib/UnicodeScalarDiagnostics.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@ func test_UnicodeScalarDoesNotImplementArithmetic(_ us: UnicodeScalar, i: Int) {
1010
isString(&a1)
1111
// We don't check for the overload choices list on the overload note match because they may change on different platforms.
1212
let a2 = "a" - "b" // expected-error {{binary operator '-' cannot be applied to two 'String' operands}}
13-
// expected-note@-1 {{overloads for '-' exist with these partially matching parameter lists:}}
1413
let a3 = "a" * "b" // expected-error {{binary operator '*' cannot be applied to two 'String' operands}}
15-
// expected-note@-1 {{overloads for '*' exist with these partially matching parameter lists:}}
1614
let a4 = "a" / "b" // expected-error {{binary operator '/' cannot be applied to two 'String' operands}}
17-
// expected-note@-1 {{overloads for '/' exist with these partially matching parameter lists:}}
1815

1916
let b1 = us + us // expected-error {{binary operator '+' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}
2017
let b2 = us - us // expected-error {{binary operator '-' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}

0 commit comments

Comments
 (0)