Skip to content

Commit 34a211d

Browse files
committed
[CSOptimizer] Exclude existential metatype candidates from paramType->isAny fast path
Refines the check to guard against existential metatypes, which would cause 'Any' to sometimes outrank 'Any.Type' candidates. Resolves #85020
1 parent 69f3ac8 commit 34a211d

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/Sema/CSOptimizer.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,11 +1429,13 @@ static void determineBestChoicesInContext(
14291429
}
14301430
}
14311431

1432-
// If the parameter is `Any` we assume that all candidates are
1433-
// convertible to it, which makes it a perfect match. The solver
1434-
// would then decide whether erasing to an existential is preferable.
1435-
if (paramType->isAny())
1436-
return 1;
1432+
// If the parameter is `Any`, it's generally a perfect match, except
1433+
// when the candidate is an existential metatype. In that case, it would
1434+
// cause (T.Type) -> (Any) disjunctions to outrank (T.Type) -> (Any.Type).
1435+
if (paramType->isAny() &&
1436+
!candidateType->is<ExistentialMetatypeType>()) {
1437+
return 1.0;
1438+
}
14371439

14381440
// Check if a candidate could be matched to a parameter by
14391441
// an existential opening.

0 commit comments

Comments
 (0)