[CSOptimizer] Allow matching against CGFloat as a contextual result type

This commit is contained in:
Pavel Yaskevich
2025-02-06 00:22:40 -08:00
parent 6c28cdfb78
commit 899b2bc1e9
3 changed files with 18 additions and 14 deletions

View File

@@ -1056,19 +1056,6 @@ static void determineBestChoicesInContext(
if (canUseContextualResultTypes() &&
(score > 0 || !hasArgumentCandidates)) {
if (llvm::any_of(resultTypes, [&](const Type candidateResultTy) {
// Avoid increasing weight based on CGFloat result type
// match because that could require narrowing conversion
// in the arguments and that is always detrimental.
//
// For example, `has_CGFloat_param(1.0 + 2.0)` should use
// `+(_: Double, _: Double) -> Double` instead of
// `+(_: CGFloat, _: CGFloat) -> CGFloat` which would match
// parameter of `has_CGFloat_param` exactly but use a
// narrowing conversion for both literals.
if (candidateResultTy->lookThroughAllOptionalTypes()
->isCGFloat())
return false;
return scoreCandidateMatch(genericSig, decl,
overloadType->getResult(),
candidateResultTy,

View File

@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -solver-scope-threshold=1000
// REQUIRES: OS=macosx
import SwiftUI

View File

@@ -0,0 +1,17 @@
// RUN: %target-typecheck-verify-swift -solver-scope-threshold=50
// REQUIRES: OS=macosx,no_asan
// REQUIRES: objc_interop
import Foundation
struct Size {
var width: CGFloat
var height: CGFloat
}
func frame(width: CGFloat?, height: CGFloat?) {}
func test(size: Size?) {
frame(width: ((size?.width ?? 0) * 1) + 1.0, height: ((size?.height ?? 0) * 1) + 1.0)
}