Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jth-0 opened this issue Mar 4, 2024 · 2 comments

Comments

@jth-0
Copy link

jth-0 commented Mar 4, 2024

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 temporalio/sdk-go#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
@jth-0 jth-0 changed the title x/tools broken in go 1.22.0 (with workaround) enumer runtime crash due to x/tools being broken in go 1.22.0 (with workaround) Mar 4, 2024
Groxx added a commit to uber/cadence that referenced this issue Apr 17, 2024
Enumer is currently crashing if `make go-generate` is run with Go 1.22: alvaroloes/enumer#71
Temporal helpfully found an easy fix: temporalio/sdk-go#1382
For the underlying cause: golang/go#62167
So I've mimicked that by just doing a `go get golang.org/x/tools@latest` in the tools-module.

And now `make clean` -> `GOTOOLCHAIN=[go1.20.1 or go1.22.1] make go-generate` both work correctly.
(you need Go 1.21 or newer to use GOTOOLCHAIN.  highly recommended!)

Since this only affects build-time tools and doesn't change any generated code, it seems trivially safe, but I have not checked what all has changed in golang.org/x/tools across these versions.
@PotatoesFall
Copy link

Awesome thanks so much 🙏

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)

@EdoaLive
Copy link

EdoaLive commented Nov 5, 2024

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)

Thanks for the fork but I think I cannot get it:

> go get  github.com/PotatoesFall/enumer  
go: github.com/PotatoesFall/enumer@upgrade (v0.0.0-20240903120707-485752ab2f44) requires github.com/PotatoesFall/enumer@v0.0.0-20240903120707-485752ab2f44: parsing go.mod:
        module declares its path as: github.com/alvaroloes/enumer
                but was required as: github.com/PotatoesFall/enumer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants