Commit Graph

4 Commits

Author SHA1 Message Date
Slava Pestov
f3e6b4ceda Sema: Disambiguate some more bidirectional conversions
This fixes an ambiguity introduced by the stdlib change in
0f99458900.

Since (borrowing T) -> () and (T) -> () both convert to
each other, we could end up with ambiguous solutions where
neither one was better than the other. Generalize the
existing trick we use for labeled vs unlabeled tuples to
also strip off ownership specifiers and @convention(...)
from function types. This fixes the regression, as well
an existing FIXME in a test I added a while ago where
the same problem arises with @convention(block).
2025-12-09 18:31:59 -05:00
Slava Pestov
1e9f8826a7 Sema: Split off Apple-specific parts of bidirectional_conversions.swift test 2025-12-09 17:35:04 -05:00
Pavel Yaskevich
69bd48e2ea [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)
2025-06-27 23:43:09 -07:00
Slava Pestov
1a38309661 Add a couple of regression tests 2025-03-11 10:20:58 -04:00