mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[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:
@@ -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()) {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user