Skip to content

Commit 030564b

Browse files
authored
Merge pull request #83703 from xedin/rdar-157644867
[CSOptimizer] All the candidates should match `Any` parameter type
2 parents af73ca3 + c46f9e4 commit 030564b

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,12 @@ static void determineBestChoicesInContext(
13881388
}
13891389
}
13901390

1391+
// If the parameter is `Any` we assume that all candidates are
1392+
// convertible to it, which makes it a perfect match. The solver
1393+
// would then decide whether erasing to an existential is preferable.
1394+
if (paramType->isAny())
1395+
return 1;
1396+
13911397
// Check protocol requirement(s) if this parameter is a
13921398
// generic parameter type.
13931399
if (genericSig && paramType->isTypeParameter()) {

test/Constraints/disfavored.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,15 @@ func test(s: String, answer: Int) {
3535
let r2c = f2(s)
3636
let _: A = r2c
3737
}
38+
39+
do {
40+
@available(*, deprecated)
41+
@_disfavoredOverload
42+
func test(v: Int) {}
43+
44+
func test(v: Any) {}
45+
46+
func call(v: Int) {
47+
test(v: v) // Ok (the overload that takes `Int` is disfavored)
48+
}
49+
}

0 commit comments

Comments
 (0)