awalterschulze / goderive

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

deriveKeys cannot deal with type alias #58

Closed deosjr closed 3 years ago

deosjr commented 3 years ago

Consider the following code:

type X struct {}

type Y map[string]*X

func test(y Y) {
    yy := map[string]*X(y)
    for _, k := range deriveSorted(deriveKeys(yy)) {
        fmt.Println(y[k])
    }
}

If we remove the typecast on y and try to use deriveKeys on y directly, removing yy entirely, goderive will fail saying:

could not yet generate: deriveSorted(deriveKeys(y))
Generator Error: keys:deriveKeys, the first argument, github.com/deosjr/test.Y, is not of type map

The first line is still shown when deriving on the typecast yy map, but derive works correctly in that case

awalterschulze commented 3 years ago

Thank you for reporting. This should be fixable using the .Underlying() method, if I recall correctly.