[swift-users] Generic factory method and type inference

Chris Lattner clattner at apple.com
Thu Mar 17 16:05:20 CDT 2016


On Mar 17, 2016, at 6:58 AM, Rudolf Adamkovič via swift-users <swift-users at swift.org> wrote:
> 
> How come I can’t call zip without explicitly specifying return type?
> 
> // ERROR: Cannot invoke `zip` with an argument list of type `(Int, Int)`
> let y = Something.zip(1, 2)
> 
> // OK: Works but it’s unacceptable to require this on caller's side
> let x = Something<(Int, Int)>.zip(1, 2)
> 
> Thank you for your time!

I know that your root problem was already answered, but FYI swift master makes it much more clear what is wrong:

test.swift:1:19: error: generic parameter 'T' could not be inferred
let y = Something.zip(1, 2)
                  ^
test.swift:1:13: note: 'T' declared as parameter to type 'Something'
final class Something<T> {
            ^

-Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160317/81ea44b9/attachment.html>


More information about the swift-users mailing list