CyborgMaster / go-codegen

Simple struct based code generation tool for go
ISC License
1 stars 3 forks source link

Panics after go 1.21 #3

Open alejo-rivera opened 2 months ago

alejo-rivera commented 2 months ago

I'm seeing panics when building/installing go-codegen with go >1.22.0. If I build using go <1.21.13 everything works as expected.

See below stack trace in the standard library.

Panic when built with go1.23.1

$ go-codegen -v
v0.7.1

$ go-codegen '~/my/cool/go/source/file.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=0x2 addr=0x0 pc=0x102d42304]

goroutine 227 [running]:
go/types.(*Checker).handleBailout(0x14000c2fdc0, 0x14000c5bc58)
        ~/sdk/go1.23.1/src/go/types/check.go:404 +0x9c
panic({0x102fe19a0?, 0x1032a21e0?})
        ~/sdk/go1.23.1/src/runtime/panic.go:785 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x103045918, 0x1032a7440})
        ~/sdk/go1.23.1/src/go/types/sizes.go:229 +0x314
go/types.(*Config).sizeof(...)
        ~/sdk/go1.23.1/src/go/types/sizes.go:334
go/types.representableConst.func1({0x103045918?, 0x1032a7440?})
        ~/sdk/go1.23.1/src/go/types/const.go:77 +0x90
go/types.representableConst({0x103048288, 0x1032997e0}, 0x14000c2fdc0, 0x1032a7440, 0x0)
        ~/sdk/go1.23.1/src/go/types/const.go:93 +0x134
go/types.(*Checker).arrayLength(0x14000c2fdc0, {0x103047798, 0x14000c486c0?})
        ~/sdk/go1.23.1/src/go/types/typexpr.go:537 +0x1bc
go/types.(*Checker).typInternal(0x14000c2fdc0, {0x1030478e8, 0x14000c3c240}, 0x0)
        ~/sdk/go1.23.1/src/go/types/typexpr.go:320 +0x3b0
go/types.(*Checker).definedType(0x14000c2fdc0, {0x1030478e8, 0x14000c3c240}, 0x14000c5b460?)
        ~/sdk/go1.23.1/src/go/types/typexpr.go:201 +0x28
go/types.(*Checker).varType(0x14000c2fdc0, {0x1030478e8, 0x14000c3c240})
        ~/sdk/go1.23.1/src/go/types/typexpr.go:166 +0x2c
go/types.(*Checker).structType(0x14000c2fdc0, 0x14000c3cc00, 0x14000c3cc00?)
        ~/sdk/go1.23.1/src/go/types/struct.go:114 +0x11c
go/types.(*Checker).typInternal(0x14000c2fdc0, {0x103047918, 0x14000c0a9a8}, 0x14000c78640)
        ~/sdk/go1.23.1/src/go/types/typexpr.go:337 +0xc20
go/types.(*Checker).definedType(0x14000c2fdc0, {0x103047918, 0x14000c0a9a8}, 0x102bf1764?)
        ~/sdk/go1.23.1/src/go/types/typexpr.go:201 +0x28
go/types.(*Checker).typeDecl(0x14000c2fdc0, 0x14000c78640, 0x1400008eb00, 0x0)
        ~/sdk/go1.23.1/src/go/types/decl.go:649 +0x454
go/types.(*Checker).objDecl(0x14000c2fdc0, {0x10304c538, 0x14000c78640}, 0x0)
        ~/sdk/go1.23.1/src/go/types/decl.go:191 +0x874
go/types.(*Checker).packageObjects(0x14000c2fdc0)
        ~/sdk/go1.23.1/src/go/types/resolver.go:702 +0x350
go/types.(*Checker).checkFiles(0x14000c2fdc0, {0x14000c4c0b8, 0x1, 0x1})
        ~/sdk/go1.23.1/src/go/types/check.go:459 +0x190
go/types.(*Checker).Files(0x1400024a000?, {0x14000c4c0b8?, 0x14000c1e540?, 0x5?})
        ~/sdk/go1.23.1/src/go/types/check.go:422 +0x80
golang.org/x/tools/go/packages.(*loader).loadPackage(0x1400024a000, 0x1400088e420)
        ~/go/pkg/mod/golang.org/x/tools@v0.1.0/go/packages/packages.go:956 +0x5dc
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
        ~/go/pkg/mod/golang.org/x/tools@v0.1.0/go/packages/packages.go:794 +0x178
sync.(*Once).doSlow(0x0?, 0x0?)
        ~/sdk/go1.23.1/src/sync/once.go:76 +0xf8
sync.(*Once).Do(...)
        ~/sdk/go1.23.1/src/sync/once.go:67
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
        ~/go/pkg/mod/golang.org/x/tools@v0.1.0/go/packages/packages.go:782 +0x48
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
        ~/go/pkg/mod/golang.org/x/tools@v0.1.0/go/packages/packages.go:789 +0x30
created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 108
        ~/go/pkg/mod/golang.org/x/tools@v0.1.0/go/packages/packages.go:788 +0x84

No panic when built with go1.23.1

$ go-codegen -v
v0.7.1

$ go-codegen '~/my/coo/go/source/file.go'
Wrote ~/my/coo/go/source/file_generated.go.
CyborgMaster commented 1 week ago

I'm pretty sure this is because the golang.org/x/tools is at version v0.1.0 while the latest is v0.27.0. This is the package that manages the parsing the go code and I bet its just so out of date that it doesn't work any more.