Admittedly, this is a bit of a quirk, but there is an explanation.
Imagine the interface{} variable as a structure consisting of two fields: one is a type and the other is data. ( []int and nil ). In fact, it looks the same as in Go runtime.
struct Iface { Itab* tab; void* data; };
When you pass your nil fragment to yes , only nil is passed as the value, so your comparison comes down to nil == nil .
Meanwhile, a call to no automatically transfers your variable to interface{} , and the call becomes something like no(interface{[]int, nil}) . Thus, a comparison in no can be considered as interface{[]int, nil} == nil , which turns out to be false in go.
The problem is really explained in Go FAQs .
justinas
source share