mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CSOptimizer] Allow matching against CGFloat as a contextual result type
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user