Consider the variadic function parameter:
func foo(bar:Int...) -> () { }
Here foo can accept multiple arguments, eg foo(5,4). I am curious about the type of Int... and its supported operations. For example, why is this invalid?
func foo2(bar2:Int...) -> () {
foo(bar2);
}
Gives a error:
Could not find an overload for '_conversion' that accepts the supplied arguments
Why is forwarding variadic parameters invalid?
What is the "conversion" the compiler is complaining about?
When you call foo, the compiler expects a series of arguments, each of which must be an Int.
In the body of foo2, bar2 summarises all the passed arguments and actually has the type Int[] for all practical purposes. Thus, you cannot pass it directly to foo — as foo wants Int arguments, and not an Int[].
As for a solution to this: see my answer to this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With