You compare two interfaces with one == two
. Let's see what the language specification has to say on the meaning of this expression:
Interface values are comparable. Two interface values are equal if
they have identical dynamic types and equal dynamic values or if both
have value nil.
Pointer values are comparable. Two pointer values are equal if they
point to the same variable or if both have value nil. Pointers to
distinct zero-size variables may or may not be equal.
In your example, both one
and two
are both interface values, and they have the same dynamic type (*fake
). Their dynamic values are both pointers to a zero-sized object though, and as you can read above, equality may or may not hold in this case.
Given this, you can solve your problem by not using pointers to zero-sized structs as unique values. Perhaps use an int
instead?
That might look like this:
type fake int
func main() {
var uniq fake
f := func() interface{} {
uniq++
return uniq
}
...
}
It's not clear what you're trying to achieve, so this may or may not be a good solution for you.