Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-24 Thread 'Axel Wagner' via golang-nuts
FWIW I believe there is enough subtlety here (small changes in the code might trigger different compiler optimizations) that I wouldn't rely too much on probing the compiler with different programs. Instead, I'd suggest decompiling the binary and/or running it in a debugger, to check what the actua

Re: [go-nuts] panic: interface conversion: interface is nil, not encoding.BinaryUnmarshaler

2024-02-24 Thread Ninja Ikta
I encountered this tricky bug today. After going through all the playground examples, I finally understood what was happening. Similar to Jochen, I was including encoding.MarshalBinary() and encoding.UnmarshalBinary() in the interface definition. A question though. Why does this bug resolve by

Re: [go-nuts] Equality of interface of an empty struct - why?

2024-02-24 Thread jake...@gmail.com
What is really fantastical is that a==b prints false, even though the pointers are actually the same. I am guessing some sort of optimization effect is at play here. https://go.dev/play/p/Dsqeh_aAXKT type Foo struct { } func main() { a := &Foo{} b := &Foo{} fmt.Printf("%t\n", *a == *b) fmt.P