jmattheis / goverter

Generate type-safe Go converters by simply defining an interface
https://goverter.jmattheis.de/
MIT License
496 stars 46 forks source link

Pointer to slice generates invalid code #40

Closed jdmeyer3 closed 1 year ago

jdmeyer3 commented 1 year ago

Describe the bug When a field of a struct contains a pointer to a slice, ie *[], it generates invalid dereference code.

To Reproduce

//go:generate go run github.com/jmattheis/goverter/cmd/goverter ...

package converter

// goverter:converter
type Converter interface {
    ConvertHouse(source DBHouseNames) APIHouseNames
}

type DBHouseNames struct {
    Names *[]string
}

type APIHouseNames struct {
    Names *[]string
}

This will end up generating code that contains invalid dereferences

...
*source.Names[i]

Expected behavior it should generate code that properly dereferences the array before attempting to use the index

(*source.Names)[i]
jmattheis commented 1 year ago

Good catch.

jmattheis commented 1 year ago

Fixed in v0.11.1.