francoispqt / gojay

high performance JSON encoder/decoder with stream API for Golang
MIT License
2.11k stars 113 forks source link

wrong code generated with custom slice types #139

Open millerlogic opened 4 years ago

millerlogic commented 4 years ago

Running this code on the codegen

package asdf

type MyInt int

type MySlice []MyInt

type Foo struct {
        Field MySlice
}

gojay -s ./asdf.go -p true -pkg asdf -t Foo

It generates code with the following:

type MySlices MySlice

func (s *MySlices) UnmarshalJSONArray(dec *gojay.Decoder) error {
    var value = {}
    if err := dec.Object(&value); err != nil {
        return err
    }
    *s = append(*s, value)
    return nil
}

Notice the var value = {} the type is incorrect (though the whole command fails because it chokes on gofmt)

Quickly looking through the code, it looks like ComponentInit is {} (and ComponentType may be empty) for the HelperType.