That’s correct, thanks for the correction. The rule only applies to parameters with argument labels.
But still, we’d lost this guarantee of self-documenting, type-safe non-emptiness if arbitrary arrays can be passed to variadic parameters with argument labels. R+ > On 8 Mar 2017, at 23:42, Derrick Ho <[email protected]> wrote: > > Rudolf, I don't believe that is a rule. > > One example includes NSLog() > > In which the first parameter is a format string and the second is a variadic > argument. The second one can be omitted. > On Wed, Mar 8, 2017 at 5:09 PM Rudolf Adamkovič via swift-evolution > <[email protected] <mailto:[email protected]>> wrote: > Correct me if I’m wrong but a variadic argument is guaranteed to have one or > more elements in the array. Isn’t that the case? As an example, consider the > following initializer: > > public init(state: State, actions: Action...) { > // ... > } > > Here, I can count on actions to be a non-empty array. It’s self-documenting > and type-safe. How would this work if arrays are (implicitly or explicitly) > convertible to variadic arguments? > > R+ > >> On 26 Feb 2017, at 17:26, Derrick Ho via swift-evolution >> <[email protected] <mailto:[email protected]>> wrote: >> > >> In swift, a variadic argument can become an array without too much effort. >> >> func foo(_ va: String...) { >> let a: [String] = va >> } >> >> However, it seems odd to me that an array can not be converted into a >> variadic argument >> >> foo(["a", "b", "c"]) // <-error >> foo("a", "b", "c") // no error >> >> Other people have wondered about this too. >> <http://stackoverflow.com/questions/24024376/passing-an-array-to-a-function-with-variable-number-of-args-in-swift> >> >> According to this thread <https://devforums.apple.com/message/970958#970958> >> Doug Gregor says it is due to some type ambiguity. with Generics. >> >> If type ambiguity is the issue, Do we have the option to cast it to the >> correct type? >> >> foo(["a", "b", "c"] as String...) // <- error. doesn't consider String... >> to be a type. >> >> What does the community think? Should we be granted some mechanism to turn >> an array into a variadic argument? > >> _______________________________________________ >> swift-evolution mailing list >> [email protected] <mailto:[email protected]> >> https://lists.swift.org/mailman/listinfo/swift-evolution >> <https://lists.swift.org/mailman/listinfo/swift-evolution> > _______________________________________________ > swift-evolution mailing list > [email protected] <mailto:[email protected]> > https://lists.swift.org/mailman/listinfo/swift-evolution > <https://lists.swift.org/mailman/listinfo/swift-evolution>
_______________________________________________ swift-evolution mailing list [email protected] https://lists.swift.org/mailman/listinfo/swift-evolution
