Go doesn't do any implicit type conversions, and it's quite consistent about that. The only things which are type "converted" are untyped constants.
I would love for this to work too, by the way, since I often come up with something like: var a []interface{} var b []SomethingConcrete I would love to be able to assign a to b without having to loop, but it won't work because their sizes are completely different, so the compiler can't emit a single conversion of this type, since one structure isn't safely coercible to the other type. This would be along the lines of reinterpret_cast<> in c++, which can corrupt memory. On Mon, Apr 13, 2020 at 6:56 PM Glen Huang <hey....@gmail.com> wrote: > Given > > type Data []byte > s := [][]byte{{1},{2}} > > I wonder why this conversion isn't allowed? > > []Data(s) > > Seems pretty straightforward. Maybe I miss some edge cases where things > won't square? > > -- > 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. > To view this discussion on the web visit > https://groups.google.com/d/msgid/golang-nuts/26c4bcfc-f67b-4638-a812-dce9c8c9b275%40googlegroups.com > <https://groups.google.com/d/msgid/golang-nuts/26c4bcfc-f67b-4638-a812-dce9c8c9b275%40googlegroups.com?utm_medium=email&utm_source=footer> > . > -- 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. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/CA%2Bv29Luzf0aY%3DzNPXpn%2BMJ-HHg%2BmTakp_aqfVk-%3DoKO7N%2BCLgw%40mail.gmail.com.