Skip to content

Equal generation requires pointer types to be generated correctly #81

@jamietanna

Description

@jamietanna

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions