matryer / moq

Interface mocking tool for go generate
http://bit.ly/meetmoq
MIT License
1.98k stars 126 forks source link

Moq panic when build with go 1.22 #212

Closed haunt98 closed 8 months ago

haunt98 commented 8 months ago

After I update to go 1.22.0, running moq is panic with runtime error: invalid memory address or nil pointer dereference.

Updating golang.org/x/tools fix the issue.

My command:

moq -out ads_mock_generated.go . AdsService

The panic:

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

goroutine 2295 [running]:
go/types.(*Checker).handleBailout(0x14000264e00, 0x1400003dbe8)
    /usr/local/go/src/go/types/check.go:367 +0x9c
panic({0x1030112c0?, 0x103240b80?})
    /usr/local/go/src/runtime/panic.go:770 +0x124
go/types.(*StdSizes).Sizeof(0x0, {0x103060238, 0x103244500})
    /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({0x103060238?, 0x103244500?})
    /usr/local/go/src/go/types/const.go:76 +0x9c
go/types.representableConst({0x103061ea8, 0x14000278ef0}, 0x14000264e00, 0x103244500, 0x0)
    /usr/local/go/src/go/types/const.go:92 +0x138
go/types.(*Checker).arrayLength(0x14000264e00, {0x1030616a8, 0x1400027b300?})
    /usr/local/go/src/go/types/typexpr.go:510 +0x238
go/types.(*Checker).typInternal(0x14000264e00, {0x1030617f8, 0x14000ec4780}, 0x0)
    /usr/local/go/src/go/types/typexpr.go:299 +0x3bc
go/types.(*Checker).definedType(0x14000264e00, {0x1030617f8, 0x14000ec4780}, 0x14000ffd3b0?)
    /usr/local/go/src/go/types/typexpr.go:180 +0x2c
go/types.(*Checker).typ(...)
    /usr/local/go/src/go/types/typexpr.go:138
go/types.(*Checker).exprInternal(0x14000264e00, 0x0, 0x14000bef740, {0x103061708, 0x140012d0900}, {0x0, 0x0})
    /usr/local/go/src/go/types/expr.go:1117 +0xc04
go/types.(*Checker).rawExpr(0x14000264e00, 0x0, 0x14000bef740, {0x103061708?, 0x140012d0900?}, {0x0?, 0x0?}, 0x0)
    /usr/local/go/src/go/types/expr.go:979 +0x12c
go/types.(*Checker).expr(0x14000264e00, 0x0?, 0x14000bef740, {0x103061708?, 0x140012d0900?})
    /usr/local/go/src/go/types/expr.go:1513 +0x38
go/types.(*Checker).varDecl(0x14000264e00, 0x140013ba000, {0x14000124758, 0x1, 0x1}, {0x0, 0x0}, {0x103061708, 0x140012d0900})
    /usr/local/go/src/go/types/decl.go:521 +0x140
go/types.(*Checker).objDecl(0x14000264e00, {0x103065498, 0x140013ba000}, 0x0)
    /usr/local/go/src/go/types/decl.go:194 +0x7ec
go/types.(*Checker).packageObjects(0x14000264e00)
    /usr/local/go/src/go/types/resolver.go:693 +0x468
go/types.(*Checker).checkFiles(0x14000264e00, {0x14000124078, 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(0x140001941c0, 0x14000375020)
    /Users/anon/go/pkg/mod/golang.org/x/tools@v0.3.0/go/packages/packages.go:1037 +0x784
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
    /Users/anon/go/pkg/mod/golang.org/x/tools@v0.3.0/go/packages/packages.go:847 +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/anon/go/pkg/mod/golang.org/x/tools@v0.3.0/go/packages/packages.go:835 +0x50
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1.1(0x0?)
    /Users/anon/go/pkg/mod/golang.org/x/tools@v0.3.0/go/packages/packages.go:842 +0x30
created by golang.org/x/tools/go/packages.(*loader).loadRecursive.func1 in goroutine 2049
    /Users/anon/go/pkg/mod/golang.org/x/tools@v0.3.0/go/packages/packages.go:841 +0x84

So I make the PR to update golang.org/x/tools.

See https://github.com/matryer/moq/pull/211 for my PR to fix