I quote So in the OP's example https://play.golang.org/p/59bpr8TCIge <https://play.golang.org/p/59bpr8TCIge>, the function A() is assigning a []string to the variadic ...[]interface{}. Since string is assignable to interface{}. this is fine. The function B() is assigning a []interface{} to the variadic of ...[]string. Since interface{} is not assignable to string, this is not allowed.
> On Oct 24, 2018, at 11:08 AM, Jan Mercl <0xj...@gmail.com> wrote: > > Nobody said that. > > On Wed, Oct 24, 2018, 18:04 robert engels <reng...@ix.netcom.com > <mailto:reng...@ix.netcom.com>> wrote: > I’m confused… it is A that doesn’t work, and B works… everyone keeps stating > that B doesn’t work and A works…. > >> On Oct 24, 2018, at 10:55 AM, jake6...@gmail.com <mailto:jake6...@gmail.com> >> wrote: > >> >> That is correct. The relevant part of >> https://golang.org/ref/spec#Passing_arguments_to_..._parameters >> <https://golang.org/ref/spec#Passing_arguments_to_..._parameters> is where >> it says: " respective parameter passing rules >> <https://golang.org/ref/spec#Passing_arguments_to_..._parameters>apply". >> This links to >> https://golang.org/ref/spec#Passing_arguments_to_..._parameters >> <https://golang.org/ref/spec#Passing_arguments_to_..._parameters> which says: >> >> "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 <https://golang.org/ref/spec#Assignability> to T." >> >> So in the OP's example https://play.golang.org/p/59bpr8TCIge >> <https://play.golang.org/p/59bpr8TCIge>, the function A() is assigning a >> []string to the variadic ...[]interface{}. Since string is assignable to >> interface{}. this is fine. The function B() is assigning a []interface{} to >> the variadic of ...[]string. Since interface{} is not assignable to string, >> this is not allowed. >> >> Hope that clarifies. >> >> >> On Wednesday, October 24, 2018 at 9:11:50 AM UTC-4, Robert Engels wrote: >> But it is the varadic one that works according to OP. >> >> On Oct 24, 2018, at 4:19 AM, Jan Mercl <0xj...@ <>gmail.com >> <http://gmail.com/>> wrote: >> >>> On Wed, Oct 24, 2018 at 7:34 AM Mayank Jha <mayank2...@ <>gmail.com >>> <http://gmail.com/>> wrote: >>> >>> > why does A() not work while B works here, >>> > https://play.golang.org/p/59bpr8TCIge >>> > <https://play.golang.org/p/59bpr8TCIge> >>> >>> Type mismatch. The compiler is clear about it: >>> >>> prog.go:8:12: cannot use s (type []string) as type []interface {} >>> in append >>> >>> From https://golang.org/ref/spec#Appending_and_copying_slices >>> <https://golang.org/ref/spec#Appending_and_copying_slices> >>> >>> ---- >>> The variadic function append appends zero or more values x to s of type S, >>> which must be a slice type, >>> and returns the resulting slice, also of type S. The values x are passed to >>> a parameter of type ...T >>> where T is the element typeof S and the respective parameter passing rules >>> apply. As a special case, >>> append also accepts a first argument assignable to type []byte with a >>> second argument of string type >>> followed by .... This form appends the bytes of the string. >>> --- >>> >>> In the OP code, type T is `interface{}`, but the appended elements have >>> type `string`. That violates the above quoted specs. >>> >>> >>> -- >>> -j >>> >>> >>> -- >>> You received this message because you are subscribed to the Google Groups >>> "golang-nuts" group. >>> To unsubscribe from this group and stop receiving emails from it, send an >>> email to golang-nuts...@ <>googlegroups.com <http://googlegroups.com/>. >>> For more options, visit https://groups.google.com/d/optout >>> <https://groups.google.com/d/optout>. >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "golang-nuts" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to golang-nuts+unsubscr...@googlegroups.com >> <mailto:golang-nuts+unsubscr...@googlegroups.com>. >> For more options, visit https://groups.google.com/d/optout >> <https://groups.google.com/d/optout>. > > > -- > You received this message because you are subscribed to the Google Groups > "golang-nuts" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to golang-nuts+unsubscr...@googlegroups.com > <mailto:golang-nuts+unsubscr...@googlegroups.com>. > For more options, visit https://groups.google.com/d/optout > <https://groups.google.com/d/optout>. > -- > -j > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.