[CSOptimizer] All the candidates should match Any parameter type

If the parameter is `Any` we assume that all candidates are
convertible to it, which makes it a perfect match. The solver
would then decide whether erasing to an existential is preferable.

Resolves: rdar://157644867
This commit is contained in:
Pavel Yaskevich
2025-08-13 14:57:22 -07:00
parent 2caa726b0b
commit c46f9e4f45
2 changed files with 18 additions and 0 deletions

View File

@@ -1388,6 +1388,12 @@ static void determineBestChoicesInContext(
}
}
// If the parameter is `Any` we assume that all candidates are
// convertible to it, which makes it a perfect match. The solver
// would then decide whether erasing to an existential is preferable.
if (paramType->isAny())
return 1;
// Check protocol requirement(s) if this parameter is a
// generic parameter type.
if (genericSig && paramType->isTypeParameter()) {

View File

@@ -35,3 +35,15 @@ func test(s: String, answer: Int) {
let r2c = f2(s)
let _: A = r2c
}
do {
@available(*, deprecated)
@_disfavoredOverload
func test(v: Int) {}
func test(v: Any) {}
func call(v: Int) {
test(v: v) // Ok (the overload that takes `Int` is disfavored)
}
}