I\'m wondering why it\'s not possible to do the following in go:
func main() {
stuff := []string{\"baz\", \"bla\"}
foo(\"bar\", stuff...)
}
func foo
The specification on this is at the "Passing arguments to ... parameters":
If
fis variadic with a final parameterpof type...T, then withinfthe type ofpis equivalent to type[]T.
Iffis invoked with no actual arguments forp, the value passed topisnil.
Otherwise, the value passed is a new slice of type[]Twith a new underlying array whose successive elements are the actual arguments, which all must be assignable toT.
In your case, where stuff... works:
If the final argument is assignable to a slice type
[]T, it may be passed unchanged as the value for a...Tparameter if the argument is followed by.... In this case no new slice is created.
But "bar", stuff... doesn't match either case specified above.
T, []T doesn't match f([]T).