easyjson icon indicating copy to clipboard operation
easyjson copied to clipboard

go 1.18 generics support

Open JILeXanDR opened this issue 3 years ago • 3 comments

I use v0.7.7, code with generics fails:

Error parsing model.go: model.go:41:27: expected ';', found '[' (and 2 more errors)
model.go:1: running "easyjson": exit status 1

Any plans to have generics support in the near future?

JILeXanDR avatar Apr 05 '22 09:04 JILeXanDR

+1 Do you have any plans for it?

skhokhlov avatar Aug 09 '22 15:08 skhokhlov

+1 At the very least generic types should be skipped for processing (potentially with a warning) instead of erroring.

dgoodine avatar Sep 01 '22 16:09 dgoodine

Are there any updates ? There are some problems with types when try to generate code that contains generics with pointer types.


Example:

package some_package;

//easyjson:json
type SecondNested struct {
	SomeField bool `json:"someField"`
}

type NestedStruct[U json.Unmarshaler] struct {
	SecondNested U `json:"secondNested"`
}

type Main[U json.Unmarshaler] struct {
	NestedStructs NestedStruct[U] `json:"nested"`
}

//easyjson:json
type SomeType struct {
	Main[*SecondNested]
}

Generated code:

func easyjson<...>SecondNested(in *jlexer.Lexer, out *NestedStruct[*some_package.SecondNested]) {}
func easyjson<...>SecondNested(out *jwriter.Writer, in NestedStruct[*some_package.SecondNested]) {}

Problem is at this type *some_package.SecondNested, there must not be some_package in type declaration.

thekudryash avatar Dec 16 '22 21:12 thekudryash