alvaroloes / enumer

A Go tool to auto generate methods for your enums
Other
478 stars 111 forks source link

enumer runtime crash due to x/tools being broken in go 1.22.0 (with workaround) #71

Open jth-0 opened 6 months ago

jth-0 commented 6 months ago

the x/tools package used by enumer causes it to generate the following error when it is built with go 1.22.0 on Mac OSX silicon.

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=0x104847480]

goroutine 169 [running]:
go/types.(*Checker).handleBailout(0x14000826000, 0x14000249c78)
    /usr/local/go/src/go/types/check.go:367 +0x9c
panic({0x10492b840?, 0x104ab2c30?})
    /usr/local/go/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x1049670f8, 0x104ab5a60})
    /usr/local/go/src/go/types/sizes.go:228 +0x320
go/types.(*Config).sizeof(...)
    /usr/local/go/src/go/types/sizes.go:333
go/types.representableConst.func1({0x1049670f8?, 0x104ab5a60?})
    /usr/local/go/src/go/types/const.go:76 +0x9c
go/types.representableConst({0x104968b98, 0x104aab660}, 0x14000826000, 0x104ab5a60, 0x0)
    /usr/local/go/src/go/types/const.go:92 +0x138
go/types.(*Checker).arrayLength(0x14000826000, {0x104968730, 0x14000320180?})
    /usr/local/go/src/go/types/typexpr.go:510 +0x238
module github.com/alvaroloes/enumer
go/types.(*Checker).typInternal(0x14000826000, {0x104967fe0, 0x1400031c0c0}, 0x0)
    /usr/local/go/src/go/types/typexpr.go:299 +0x3bc
go/types.(*Checker).definedType(0x14000826000, {0x104967fe0, 0x1400031c0c0}, 0x14000249238?)
    /usr/local/go/src/go/types/typexpr.go:180 +0x2c
go/types.(*Checker).varType(0x14000826000, {0x104967fe0, 0x1400031c0c0})
    /usr/local/go/src/go/types/typexpr.go:145 +0x2c
go/types.(*Checker).structType(0x14000826000, 0x14000818270, 0x14000818270?)
    /usr/local/go/src/go/types/struct.go:113 +0x128
module github.com/alvaroloes/enumer
go/types.(*Checker).typInternal(0x14000826000, {0x104968010, 0x1400031a9f0}, 0x14000822320)
    /usr/local/go/src/go/types/typexpr.go:316 +0xed0
go/types.(*Checker).definedType(0x14000826000, {0x104968010, 0x1400031a9f0}, 0x1046ac1e4?)
    /usr/local/go/src/go/types/typexpr.go:180 +0x2c
go/types.(*Checker).typeDecl(0x14000826000, 0x14000822320, 0x1400037c080, 0x0)
    /usr/local/go/src/go/types/decl.go:615 +0x39c
go/types.(*Checker).objDecl(0x14000826000, {0x10496abb8, 0x14000822320}, 0x0)
    /usr/local/go/src/go/types/decl.go:197 +0x880
go/types.(*Checker).packageObjects(0x14000826000)
    /usr/local/go/src/go/types/resolver.go:681 +0x3c0
go/types.(*Checker).checkFiles(0x14000826000, {0x1400030e008, 0x1, 0x1})
    /usr/local/go/src/go/types/check.go:408 +0x164
go/types.(*Checker).Files(...)
    /usr/local/go/src/go/types/check.go:372
golang.org/x/tools/go/packages.(*loader).loadPackage(0x140000c22c0, 0x1400040b8a0)
    /Users/johnpaulhumphrey/go/pkg/mod/golang.org/x/tools@v0.0.0-20190525145741-7be61e1b0e51/go/packages/packages.go:825 +0x4f4
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
    /Users/johnpaulhumphrey/go/pkg/mod/golang.org/x/tools@v0.0.0-20190525145741-7be61e1b0e51/go/packages/packages.go:683 +0x178
sync.(*Once).doSlow(0x0?, 0x0?)
    /usr/local/go/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
    /usr/local/go/src/sync/once.go:65
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
    /Users/johnpaulhumphrey/go/pkg/mod/golang.org/x/tools@v0.0.0-20190525145741-7be61e1b0e51/go/packages/packages.go:670 +0x50
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
    /Users/johnpaulhumphrey/go/pkg/mod/golang.org/x/tools@v0.0.0-20190525145741-7be61e1b0e51/go/packages/packages.go:677 +0x30
created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 40
    /Users/johnpaulhumphrey/go/pkg/mod/golang.org/x/tools@v0.0.0-20190525145741-7be61e1b0e51/go/packages/packages.go:676 +0x84

As you can see these errors come from x/tools not enumer

the workaround

per https://github.com/temporalio/sdk-go/issues/1382 we need to update x/tools in go mod to a later version

I edited enumer/go.mod to

module github.com/alvaroloes/enumer

go 1.17 // bumped to later version

require (
    github.com/pascaldekloe/name v0.0.0-20180628100202-0fd16699aae1
    golang.org/x/tools v0.17.0 //was v0.0.0-20190525145741-7be61e1b0e51
)

require golang.org/x/mod v0.14.0 // indirect
PotatoesFall commented 1 week ago

Awesome thanks so much :pray:

Is there a fork of this repo that is still actively developed?

I made my own fork with the above changes if anybody wants to use it: https://github.com/PotatoesFall/enumer

(I make no guarantees to keep this up until the end of time)