From: Robert Griesemer Date: Thu, 6 Mar 2014 18:35:05 +0000 (-0800) Subject: spec: clarify value passed for final parameter of variadic functions X-Git-Tag: go1.3beta1~443 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a76627774272c7278819f3e5a9990c7a00183882;p=gostls13.git spec: clarify value passed for final parameter of variadic functions NOT A LANGUAGE CHANGE. Fixes #7073. LGTM=r R=r, rsc, iant, ken CC=golang-codereviews https://golang.org/cl/68840045 --- diff --git a/doc/go_spec.html b/doc/go_spec.html index b89aafebe7..0bf9d1da93 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -2915,27 +2915,32 @@ There is no distinct method type and there are no method literals.

Passing arguments to ... parameters

-If f is variadic with final parameter type ...T, -then within the function the argument is equivalent to a parameter of type -[]T. At each call of f, the argument -passed to the final parameter is -a new slice of type []T whose successive elements are -the actual arguments, which all must be assignable -to the type T. The length of the slice is therefore the number of -arguments bound to the final parameter and may differ for each call site. +If f is variadic with a final +parameter p of type ...T, then within f +the type of p is equivalent to type []T. +If f is invoked with no actual arguments for p, +the value passed to p is nil. +Otherwise, the value passed is a new slice +of type []T with a new underlying array whose successive elements +are the actual arguments, which all must be assignable +to T. The length and capacity of the slice is therefore +the number of arguments bound to p and may differ for each +call site.

-Given the function and call +Given the function and calls

 func Greeting(prefix string, who ...string)
+Greeting("nobody")
 Greeting("hello:", "Joe", "Anna", "Eileen")
 

within Greeting, who will have the value -[]string{"Joe", "Anna", "Eileen"} +nil in the first call, and +[]string{"Joe", "Anna", "Eileen"} in the second.