BurntSushi/go-sumtype

panic with runtime error

xuxinx opened this issue · 0 comments

Hi, thanks for this wonderful tool!
I am using Go1.22.1. When I use it in a large project, it panics:

$ go-sumtype $(go list ./... | grep -v vendor)
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=0x104f64824]

goroutine 287 [running]:
go/types.(*Checker).handleBailout(0x1400039c200, 0x1400147fbe8)
        /opt/homebrew/opt/go/libexec/src/go/types/check.go:367 +0x9c
panic({0x10506fd20?, 0x1051f67c0?})
        /opt/homebrew/opt/go/libexec/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x1050ad4d8, 0x1051f93e0})
        /opt/homebrew/opt/go/libexec/src/go/types/sizes.go:228 +0x314
go/types.(*Config).sizeof(...)
        /opt/homebrew/opt/go/libexec/src/go/types/sizes.go:333
go/types.representableConst.func1({0x1050ad4d8?, 0x1051f93e0?})
        /opt/homebrew/opt/go/libexec/src/go/types/const.go:76 +0x9c
go/types.representableConst({0x1050ae5c0, 0x1051ef000}, 0x1400039c200, 0x1051f93e0, 0x1400147dfe8)
        /opt/homebrew/opt/go/libexec/src/go/types/const.go:92 +0x138
go/types.(*Checker).representation(0x1400039c200, 0x140002c24c0, 0x1051f93e0)
        /opt/homebrew/opt/go/libexec/src/go/types/const.go:256 +0x68
go/types.(*Checker).implicitTypeAndValue(0x1400039c200, 0x140002c24c0, {0x1050ad4d8, 0x1051f93e0})
        /opt/homebrew/opt/go/libexec/src/go/types/expr.go:375 +0x304
go/types.(*Checker).convertUntyped(0x1400039c200, 0x140002c24c0, {0x1050ad4d8, 0x1051f93e0})
        /opt/homebrew/opt/go/libexec/src/go/types/const.go:289 +0x30
go/types.(*Checker).matchTypes(0x1400039c200, 0x140002c2400, 0x140002c24c0)
        /opt/homebrew/opt/go/libexec/src/go/types/expr.go:926 +0x7c
go/types.(*Checker).binary(0x1400039c200, 0x140002c2400, {0x1050add10, 0x140006242a0}, {0x1050ad980, 0x14000906760}, {0x1050ae190, 0x14000906780}, 0x2d, 0x1400cf)
        /opt/homebrew/opt/go/libexec/src/go/types/expr.go:800 +0x114
go/types.(*Checker).exprInternal(0x1400039c200, 0x0, 0x140002c2400, {0x1050add10, 0x140006242a0}, {0x0, 0x0})
        /opt/homebrew/opt/go/libexec/src/go/types/expr.go:1416 +0x1d4
go/types.(*Checker).rawExpr(0x1400039c200, 0x0, 0x140002c2400, {0x1050add10?, 0x140006242a0?}, {0x0?, 0x0?}, 0x0)
        /opt/homebrew/opt/go/libexec/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).expr(0x1400039c200, 0x1050ad2a8?, 0x140002c2400, {0x1050add10?, 0x140006242a0?})
        /opt/homebrew/opt/go/libexec/src/go/types/expr.go:1513 +0x38
go/types.(*Checker).stmt(0x1400039c200, 0x0, {0x1050ae010, 0x14000986c40})
        /opt/homebrew/opt/go/libexec/src/go/types/stmt.go:570 +0xda4
go/types.(*Checker).stmtList(0x1400039c200, 0x0, {0x14000906940?, 0x1?, 0x1481580254add91?})
        /opt/homebrew/opt/go/libexec/src/go/types/stmt.go:121 +0x88
go/types.(*Checker).funcBody(0x1400039c200, 0x1050acba0?, {0x14000b813b0?, 0x14000024160?}, 0x140002c20c0, 0x140006243c0, {0x0?, 0x0?})
        /opt/homebrew/opt/go/libexec/src/go/types/stmt.go:41 +0x21c
go/types.(*Checker).funcDecl.func1()
        /opt/homebrew/opt/go/libexec/src/go/types/decl.go:852 +0x44
go/types.(*Checker).processDelayed(0x1400039c200, 0x0)
        /opt/homebrew/opt/go/libexec/src/go/types/check.go:467 +0x12c
go/types.(*Checker).checkFiles(0x1400039c200, {0x1400094e4b8, 0x1, 0x1})
        /opt/homebrew/opt/go/libexec/src/go/types/check.go:411 +0x188
go/types.(*Checker).Files(...)
        /opt/homebrew/opt/go/libexec/src/go/types/check.go:372
golang.org/x/tools/go/packages.(*loader).loadPackage(0x140000f4000, 0x140008bd050)
        /Users/xuxin/go/pkg/mod/golang.org/x/tools@v0.2.0/go/packages/packages.go:1037 +0x784
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
        /Users/xuxin/go/pkg/mod/golang.org/x/tools@v0.2.0/go/packages/packages.go:847 +0x178
sync.(*Once).doSlow(0x0?, 0x0?)
        /opt/homebrew/opt/go/libexec/src/sync/once.go:74 +0x100
sync.(*Once).Do(...)
        /opt/homebrew/opt/go/libexec/src/sync/once.go:65
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
        /Users/xuxin/go/pkg/mod/golang.org/x/tools@v0.2.0/go/packages/packages.go:835 +0x50
golang.org/x/tools/go/packages.(*loader).refine.func2(0x0?)
        /Users/xuxin/go/pkg/mod/golang.org/x/tools@v0.2.0/go/packages/packages.go:770 +0x30
created by golang.org/x/tools/go/packages.(*loader).refine in goroutine 1
        /Users/xuxin/go/pkg/mod/golang.org/x/tools@v0.2.0/go/packages/packages.go:769 +0xaa4

After I tried upgrading all dep packages, this panic disappeared and it works perfectly.
I have created a PR, could you please review it?