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

Russ Bishop xenadu at gmail.com
Fri Feb 26 16:28:12 CST 2016


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


More information about the swift-evolution mailing list