You are comparing two interfaces with one == two . Let's see what the language specification says by the meaning of this expression:
Interface values ββare comparable. Two interface values ββare equal if they have the same dynamic types and equal dynamic values, or if both are nil.
The pointer values ββare comparable. Two pointer values ββare equal if they point to the same variable or both are nil. Pointers to various variables of zero size may or may not be equal.
In your example, both the one and two values ββare the values ββof both interfaces, and they have the same dynamic type ( *fake ). Their dynamic values ββare simultaneously pointers to an object with a zero size, and, as you can read above, in this case there may or may not be equality.
Given this, you can solve your problem by not using pointers for structures with zero size as unique values. Perhaps use int instead?
It might look like this:
type fake int func main() { var uniq fake f := func() interface{} { uniq++ return uniq } ... }
It is not clear what you are trying to achieve, so this may or may not be a good solution for you.
source share