Eh, actially the other discusser said that. Me not. I explained why A does
not work.

On Wed, Oct 24, 2018, 18:08 Jan Mercl <[email protected]> wrote:

> Nobody said that.
>
> On Wed, Oct 24, 2018, 18:04 robert engels <[email protected]> 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, [email protected] wrote:
>>
>>
>> That is correct. The relevant part of
>> 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 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, 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 <[email protected]> wrote:
>>>
>>> On Wed, Oct 24, 2018 at 7:34 AM Mayank Jha <[email protected]> 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 [email protected].
>>> For more options, visit 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 [email protected].
>> For more options, visit 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 [email protected].
>> For more options, visit https://groups.google.com/d/optout.
>>
> --
>
> -j
>
-- 

-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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to