Open jamietanna opened 1 year ago
Following the example code on the README:
type MyStruct struct { Int64 int64 StringPtr *string } func (this *MyStruct) Equal(that *MyStruct) bool { return deriveEqual(this, that) } // alternatively func (this MyStruct) Equal(that MyStruct) bool { return deriveEqual(&this, &that) }
Results in:
func deriveEqual(this, that *MyStruct) bool { return (this == nil && that == nil) || this != nil && that != nil && this.Int64 == that.Int64 && ((this.StringPtr == nil && that.StringPtr == nil) || (this.StringPtr != nil && that.StringPtr != nil && *(this.StringPtr) == *(that.StringPtr))) }
However, when this uses a non-pointer receiver:
func (this MyStruct) Equal(that MyStruct) bool { return deriveEqual(this, that) }
This generates:
func deriveEqual(this, that MyStruct) bool { return ((&this == nil && &that == nil) || (&this != nil && &that != nil && (*(&this)).Equal(*(&that)))) }
Which doesn't perform the same checks?
Still technically correct, but you are right, we could do better here, by not doing the checks
Doesn't seem even technically correct because it causes infinite recursion and a stack overflow.
Following the example code on the README:
Results in:
However, when this uses a non-pointer receiver:
This generates:
Which doesn't perform the same checks?