Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-13453] Type inference fails for trailing closure when overloading is also involved (Swift 5.0-5.3) #55895

Open
swift-ci opened this issue Aug 26, 2020 · 0 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-13453
Radar None
Original Reporter andersha (JIRA User)
Type Bug
Environment

Tried with:

  1. Linux Swift 5.0.1 toolchain,
  2. Xcode 11.5
  3. Xcode 12 beta 5
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: e1df46361e9514af8ed6c264016aa6e5

Issue Description:

Trailing closure is used on a base name that involves two overloads, where one is generic `<U> (U) -> Dummy<U>` while another being a more specific `<U> ((Self.T0) -> U) -> Dummy<U>`.

In this scenario, the type checker is not able to resolve/infer the return type, leading to an "ambiguous reference" message being presented.

Not sure if this is related to https://bugs.swift.org/browse/SR-6989, but the bug impacts the same use case.

struct A<U> {}
extension A {
    func map<T>(_ transform: (U) -> T) -> A<T> { A<T>() }
    func map<T>(value: T) -> A<T> { A<T>() }
}

let value = A<Int>()

// OK
let r0: A<Double> = value.map { Double($0) }
let r2 = value.map(value: Double(1))

// Failing case, works if return type is explicit (as `r0` above)
let r1 = value.map { Double($0) }

Xcode 11.5 and Xcode 12 beta 5

error: Swift53Overload.playground:9:22: error: ambiguous use of 'init(_:)'
let r1 = value.map { Double($0) }

Linux Swift 5.0.1

main.swift:3:53: warning: result of 'A<U>' initializer is unused
    func map<T>(_ transform: (U) -> T) -> A<T> { A<T>() }
                                                    ^~~
main.swift:4:40: warning: result of 'A<U>' initializer is unused
    func map<T>(value: T) -> A<T> { A<T>() }
                                       ^~~
main.swift:9:22: error: ambiguous use of 'init(_:)'
let r1 = value.map { Double($0) }
                     ^
Swift.Double:2:12: note: found this candidate
    public init(_ v: Int)
           ^
Swift.Double:3:23: note: found this candidate
    @inlinable public init<Source>(_ value: Source) where Source : BinaryInteger
                      ^
Swift.BinaryFloatingPoint:3:23: note: found this candidate
    @inlinable public init<Source>(_ value: Source) where Source : BinaryInteger
                      ^
Swift.Double:4:12: note: found this candidate
    public init(_ _value: FPIEEE64)
           ^
Swift.Double:4:23: note: found this candidate
    @inlinable public init(_ other: Float)
                      ^
Swift.Double:6:23: note: found this candidate
    @inlinable public init(_ other: Double)
                      ^
Swift.Double:8:23: note: found this candidate
    @inlinable public init(_ other: Float80)
                      ^
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself
Projects
None yet
Development

No branches or pull requests

1 participant