mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSOptimizer] Fix Double<->CGFloat implicit conversion support when arguments are literals
Passing Double to CGFloat as well as vice versa constitutes an exact match.
This commit is contained in:
@@ -454,7 +454,15 @@ static Constraint *determineBestChoicesInContext(
|
||||
scoreCandidateMatch = [&](GenericSignature genericSig,
|
||||
Type candidateType, Type paramType,
|
||||
MatchOptions options) -> double {
|
||||
auto areEqual = [](Type a, Type b) {
|
||||
auto areEqual = [&options](Type a, Type b) {
|
||||
// Double<->CGFloat implicit conversion support for literals
|
||||
// only since in this case the conversion might not result in
|
||||
// score penalty.
|
||||
if (options.contains(MatchFlag::Literal) &&
|
||||
((a->isDouble() && b->isCGFloat()) ||
|
||||
(a->isCGFloat() && b->isDouble())))
|
||||
return true;
|
||||
|
||||
return a->getDesugaredType()->isEqual(b->getDesugaredType());
|
||||
};
|
||||
|
||||
@@ -462,11 +470,13 @@ static Constraint *determineBestChoicesInContext(
|
||||
return areEqual(candidateType, paramType) ? 1 : 0;
|
||||
|
||||
// Exact match between candidate and parameter types.
|
||||
if (areEqual(candidateType, paramType))
|
||||
if (areEqual(candidateType, paramType)) {
|
||||
return options.contains(MatchFlag::Literal) ? 0.3 : 1;
|
||||
}
|
||||
|
||||
if (options.contains(MatchFlag::Literal))
|
||||
if (options.contains(MatchFlag::Literal)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Check whether match would require optional injection.
|
||||
{
|
||||
|
||||
@@ -361,3 +361,8 @@ do {
|
||||
return v // Ok
|
||||
}
|
||||
}
|
||||
|
||||
func test_cgfloat_operator_is_attempted_with_literal_arguments(v: CGFloat?) {
|
||||
let ratio = v ?? (2.0 / 16.0)
|
||||
let _: CGFloat = ratio // Ok
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user