In my defense, neither A() nor B() complies in the actual example given. If 
you comment out A() you will see that B() then fails to compile. 

If B() is fixed by replacing "i = append(i, s)" with "i = append(i, sa)", 
then it succeeds. I believe that is due to the clause I referenced in my 
mistaken post.That is 
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."

This refers to the case when individual arguments are given. In this case a 
string is assignable to an interface{}. 

IIUC A() fails because later in that section it says:

"If the final argument is assignable to a slice type []T, it may be passed 
unchanged as the value for a ...T parameter if the argument is followed by 
.... In this case no new slice is created."

And as we know []string is not assignable to []interface{}.

Hope that makes more sense than my original post.



On Thursday, October 25, 2018 at 12:01:21 PM UTC-4, Robert Engels wrote:
>
> No need. I was just getting very confused trying to follow. 
>
> On Oct 25, 2018, at 10:59 AM, jake...@gmail.com <javascript:> wrote:
>
> Yes. I was completely mistaken in my post. Apologies. 
>
> On Wednesday, October 24, 2018 at 12:14:36 PM UTC-4, robert engels wrote:
>>
>> I quote
>>
>> 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. 
>>
>>
>> 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 <ren...@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, jake...@gmail.com 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 <0xj...@gmail.com> wrote:
>>>>
>>>> On Wed, Oct 24, 2018 at 7:34 AM Mayank Jha <mayank2...@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...@googlegroups.com.
>>>> 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 golang-nuts...@googlegroups.com.
>>> 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 golang-nuts...@googlegroups.com.
>>> For more options, visit 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...@googlegroups.com <javascript:>.
> 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 golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to