Swift: variadic parameters do not convert to variadic tuples
| Originator: | rix.rob | ||
| Number: | rdar://17493920 | Date Originated: | 27-Jun-2014 11:12 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode6-Beta2 (6A216f) |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
The type of a variadic function of T returning U is (T...) -> U; (T...) is a valid (variadic) tuple type; but variadic parameters are arrays. This is syntactically weird and semantically uncomfortable.
Steps to Reproduce:
1. Write the following function:
func apply<T>(a: T...) -> (T...) {
return a
}
2. Note that it appears to take a variadic parameter list and return a 1-tuple with a variadic list.
3. Try to compile it; make it return (a) instead and try again.
Expected Results:
Success with at least one of the two attempts.
Actual Results:
Both fail: error: could not find an overload for '__conversion' that accepts the supplied arguments.
Regression:
N/A
Notes:
So, it *looks* like it should work, but it doesn’t. However, this version works just fine:
func apply<T>(a: (T...)) -> (T...) {
return a
}
Since you can’t write the return type T... without the parens, and given the different behaviour of T... in the parameter list vs. alone, it’s clear that variadic parameters and variadic tuple types are distinct. There appears to be no way to return a variadic tuple given a variadic parameter, either.
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!