awalterschulze / goderive

Derives and generates mundane golang functions that you do not want to maintain yourself
Apache License 2.0
1.23k stars 44 forks source link

Fix string aliases in deriveCompare #86

Closed gavv closed 2 months ago

gavv commented 3 months ago

Thanks for sharing this tool.

I've encountered a bug: if a field is a type alias to string, generated compare function will have this:

    if c := strings.Compare(this.Foo, that.Foo); c != 0 {
        return c
    }

which doesn't compile:

cannot use this.Foo (variable of type StringAlias) as string value in argument to strings.Compare

This PR fixes it by changing the generated code to:

    if c := strings.Compare(string(this.Foo), string(that.Foo)); c != 0 {
        return c
    }
awalterschulze commented 2 months ago

Thank you so much for the fix and unit test <3 Sorry for the long wait