mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[CSSimplify] CGFloat-Double: Rank narrowing correctly when result is injected into an optional
If result of `CGFloat` -> `Double` conversion is injected into an optional
it should be ranked based on depth just like when locator is fully simplified.
For example:
```swift
func test(v: CGFloat?) {
_ = v ?? 2.0 / 3.0
}
```
In this expression division should be performed on `Double` and result
narrowed down (based on the rule that narrowing conversion should always
be delayed) but `Double` -> `CGFloat?` was given an incorrect score and
instead of picking `?? (_: T?, _: T) -> T` overload, the solver would
use `?? (_: T?, _: T?) -> T?`.
(cherry picked from commit cb876cbd9e)
This commit is contained in:
@@ -6,7 +6,7 @@ import CoreGraphics
|
||||
|
||||
/////////////
|
||||
|
||||
struct G<T> { // expected-note {{arguments to generic parameter 'T' ('CGFloat?' and 'CGFloat') are expected to be equal}}
|
||||
struct G<T> {
|
||||
var t: T
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ func foo4(x: (() -> ())?, y: @escaping @convention(block) () -> ()) -> G<() -> (
|
||||
|
||||
func foo5(x: CGFloat?, y: Double) -> G<CGFloat> {
|
||||
let g = G(t: x ?? y)
|
||||
// FIXME
|
||||
return g // expected-error {{cannot convert return expression of type 'G<CGFloat?>' to return type 'G<CGFloat>'}}
|
||||
return g
|
||||
}
|
||||
|
||||
func foo6(x: Double?, y: CGFloat) -> G<Double> {
|
||||
|
||||
Reference in New Issue
Block a user