fjl / gencodec

Command gencodec generates marshaling methods for Go struct types.
MIT License
55 stars 27 forks source link

Something broken with go1.22 #24

Open gballet opened 4 months ago

gballet commented 4 months ago

I try to generate the ExecutionPayload json encoder in this branch with go 1.22, and I get the following stack trace:

> go run github.com/fjl/gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x5a9fcf]

goroutine 241 [running]:
go/types.(*Checker).handleBailout(0xc000332600, 0xc001411bd0)
    /usr/local/go/src/go/types/check.go:367 +0x88
panic({0x6eebc0?, 0x994f50?})
    /usr/local/go/src/runtime/panic.go:770 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0x7cce98, 0x998780})
    /usr/local/go/src/go/types/sizes.go:228 +0x30f
go/types.(*Config).sizeof(...)
    /usr/local/go/src/go/types/sizes.go:333
go/types.representableConst.func1({0x7cce98?, 0x998780?})
    /usr/local/go/src/go/types/const.go:76 +0x9e
go/types.representableConst({0x7cebe0, 0x98d7e0}, 0xc000332600, 0x998780, 0xc0014107e8)
    /usr/local/go/src/go/types/const.go:92 +0x192
go/types.(*Checker).representation(0xc000332600, 0xc000312380, 0x998780)
    /usr/local/go/src/go/types/const.go:256 +0x65
go/types.(*Checker).implicitTypeAndValue(0xc000332600, 0xc000312380, {0x7cce98, 0x998780})
    /usr/local/go/src/go/types/expr.go:375 +0x2d7
go/types.(*Checker).assignment(0xc000332600, 0xc000312380, {0x7cce98, 0x998780}, {0x75187e, 0x10})
    /usr/local/go/src/go/types/assignments.go:52 +0x2e5
go/types.(*Checker).initVar(0xc000332600, 0xc000320fc0, 0xc000312380, {0x75187e, 0x10})
    /usr/local/go/src/go/types/assignments.go:163 +0x3b2
go/types.(*Checker).initVars(0xc000332600, {0xc000324050, 0x1, 0xc0000fa338?}, {0xc0002820f0, 0xc000e68d58?, 0x49d546ad5ca5b230?}, {0x7ce360, 0xc0004e27c0})
    /usr/local/go/src/go/types/assignments.go:382 +0x638
go/types.(*Checker).stmt(0xc000332600, 0x0, {0x7ce360, 0xc0004e27c0})
    /usr/local/go/src/go/types/stmt.go:524 +0x1fc5
go/types.(*Checker).stmtList(0xc000332600, 0x0, {0xc000282100?, 0x0?, 0x0?})
    /usr/local/go/src/go/types/stmt.go:121 +0x85
go/types.(*Checker).funcBody(0xc000332600, 0x7cce98?, {0xc000126354?, 0x998780?}, 0xc000312300, 0xc00080a9c0, {0x0?, 0x0?})
    /usr/local/go/src/go/types/stmt.go:41 +0x331
go/types.(*Checker).funcDecl.func1()
    /usr/local/go/src/go/types/decl.go:852 +0x3a
go/types.(*Checker).processDelayed(0xc000332600, 0x0)
    /usr/local/go/src/go/types/check.go:467 +0x162
go/types.(*Checker).checkFiles(0xc000332600, {0xc000282030, 0x2, 0x2})
    /usr/local/go/src/go/types/check.go:411 +0x1cc
go/types.(*Checker).Files(...)
    /usr/local/go/src/go/types/check.go:372
golang.org/x/tools/go/packages.(*loader).loadPackage(0xc0001b01c0, 0xc000351c80)
    /home/gballet/go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:1052 +0xa72
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
    /home/gballet/go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:851 +0x1a9
sync.(*Once).doSlow(0x0?, 0x0?)
    /usr/local/go/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
    /usr/local/go/src/sync/once.go:65
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
    /home/gballet/go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:839 +0x4a
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
    /home/gballet/go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:846 +0x26
created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 163
    /home/gballet/go/pkg/mod/golang.org/x/tools@v0.9.1/go/packages/packages.go:845 +0x94
exit status 2

With go 1.21, everything works fine.