[Idea] Remove variadic parameters or pass an array of matching type through to the callee


(Russ Bishop) #1

We’ve been bitten by this bug now a couple of times where an open-ended variadic parameter ends up accepting an array as a single parameter rather than treating the array as having .count parameters. In some cases these are APIs we don’t control so it makes it difficult to have the compiler catch the errors.

I lean toward allowing a single parameter in the variadic position and with a compatible type to be passed-through to the callee because it means you can chain variadic parameters. It does prevent you from passing a Swift array if that’s the only parameter you need but in Swift we have many tools to solve that problem.

C# already allows this. In fact you declare the variadic as `params string[] someStrings` instead of using `…` so the decl syntax is explicit (but that’s another bikeshed). The benefit is that it’s obvious that passing a string array will pass-through to the callee and variadics can be seen simply as implicit array literals.

Russ


(Joe Groff) #2

This sounds like a bug. Do you have an example?

-Joe

···

On Feb 26, 2016, at 2:28 PM, Russ Bishop via swift-evolution <swift-evolution@swift.org> wrote:

We’ve been bitten by this bug now a couple of times where an open-ended variadic parameter ends up accepting an array as a single parameter rather than treating the array as having .count parameters. In some cases these are APIs we don’t control so it makes it difficult to have the compiler catch the errors.