Covariance does not work for functions with variadic arguments
Originator: | Nikita.Leonov | ||
Number: | rdar://23011851 | Date Originated: | |
Status: | Open | Resolved: | |
Product: | Development Tools | Product Version: | |
Classification: | Other Bug | Reproducible: | Always |
Summary: Swift 2.1 covariance unable to resolve functions covariance with variadic arguments. Steps to Reproduce: Attached a playground that shows the problem, as well as screenshot with errors. Here is a copy & paste of the code for your convenience: func giveMeVoid(callback: (Void)->Void) { } func giveMeInt(callback: (Int)->Void) { } func any(values:Any?...) { } any() any(5) giveMeVoid(any) //This line will fail giveMeInt(any) //This line will fail Expected Results: It is expected that `any` will be accepted by both giveMeVoid and giveMeInt functions, as they can work as `Void` and `Int` functions when they called directly. Actual Results: Non of functions accept 'any'. Following errors are thrown: error: cannot convert value of type '(Any?...) -> ()' to expected argument type '(Void) -> Void' error: cannot convert value of type '(Any?...) -> ()' to expected argument type '(Int) -> Void' Version: Xcode 7.1 beta 3 (7B85) Notes: Configuration: Reproducible in Swift 2 & 2.1 on every beta. Attachments: 'covariance.playground.zip' and 'variadic-covariance.png' were successfully uploaded.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!