Difference between fmt.* and the compiler regarding []interface{}

i opened an issue and it took a minute to close it. but i don’t get it. there is a difference between what fmt.* does and what the compiler says. (edit: to be clear: it’s a bug in fmt, not the compiler!) i call that a bug and i have to work around it now…

well here it is: (Sorry, new users can only put 2 links in a post. great work on that one, guys! it implements the github issue which has more then 2 links and thats my fault. another workaround needed… sigh)

http s://github.com/golang/go/issues/14695

can anyone put me up on the why part?

interestingly bradfitz just removed his comment: “it’s also not a bug in fmt”

LGTM. T.atype is []interface{} - the output is correct.

In your example the exact type of ss is only known at runtime, not at compile time.

You’re passing tes() an []interface{}{"test"} (the “atype”). This get’s wrapped in another []interface{} due to the ...interface{} parameter type. Hence s in tes() becomes an []interface{} containing an []interface{} containing a string.

(You’re also getting lost in a twisty maze of interface{}s which is not a good idea, especially when starting out. Try to use narrower types.)

1 Like

thank you calmh and kostya_sh!

i missed three dots in te() calling tes()! silly me.

 func te(Te *T) { 
     tes(Te.atype...)
 }

[]interface {}, string = acdc
[]interface {}, string = test

https://play.golang.org/p/Dt7ynl6b8I

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.