On Wed, Oct 24, 2018 at 7:34 AM Mayank Jha <mayank25080...@gmail.com> wrote:

> why does A() not work while B works here,
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

----
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+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to