vektra / mockery

A mock code autogenerator for Go
https://vektra.github.io/mockery/
BSD 3-Clause "New" or "Revised" License
5.8k stars 395 forks source link

mockery built with go 1.22~rc2 fails #752

Closed darix closed 4 months ago

darix commented 4 months ago

Description

+ set -e
+ ARCHIVE=resticprofile-0.24.0.tar.gz
+ DIRNAME=resticprofile-0.24.0
+ '[' -d resticprofile-0.24.0 ']'
+ tar xf resticprofile-0.24.0.tar.gz
+ cd resticprofile-0.24.0
+ mockery --config .mockery.yaml
04 Feb 24 00:39 CET INF Starting mockery dry-run=false version=2.40.1
04 Feb 24 00:39 CET INF Using config: .mockery.yaml dry-run=false version=2.40.1
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=0x1 addr=0x0 pc=0x5575a29f8fde]

goroutine 51 [running]:
go/types.(*Checker).handleBailout(0xc0000ea600, 0xc000cd3bd0)
    /usr/lib64/go/1.22/src/go/types/check.go:367 +0x88
panic({0x5575a2d58cc0?, 0x5575a30ef3c0?})
    /usr/lib64/go/1.22/src/runtime/panic.go:770 +0x132
go/types.(*StdSizes).Sizeof(0x0, {0x5575a2dd2dc8, 0x5575a30f4300})
    /usr/lib64/go/1.22/src/go/types/sizes.go:228 +0x31e
go/types.(*Config).sizeof(...)
    /usr/lib64/go/1.22/src/go/types/sizes.go:333
go/types.representableConst.func1({0x5575a2dd2dc8?, 0x5575a30f4300?})
    /usr/lib64/go/1.22/src/go/types/const.go:76 +0x9e
go/types.representableConst({0x5575a2dd56c8, 0x5575a30cbf98}, 0xc0000ea600, 0x5575a30f4300, 0xc000cd0738)
    /usr/lib64/go/1.22/src/go/types/const.go:92 +0x192
go/types.(*Checker).representation(0xc0000ea600, 0xc000c97980, 0x5575a30f4300)
    /usr/lib64/go/1.22/src/go/types/const.go:256 +0x65
go/types.(*Checker).implicitTypeAndValue(0xc0000ea600, 0xc000c97980, {0x5575a2dd2dc8, 0x5575a30f4300})
    /usr/lib64/go/1.22/src/go/types/expr.go:375 +0x30d
go/types.(*Checker).convertUntyped(0xc0000ea600, 0xc000c97980, {0x5575a2dd2dc8, 0x5575a30f4300})
    /usr/lib64/go/1.22/src/go/types/const.go:289 +0x3f
go/types.(*Checker).matchTypes(0xc0000ea600, 0xc000c97940, 0xc000c97980)
    /usr/lib64/go/1.22/src/go/types/expr.go:926 +0x79
go/types.(*Checker).binary(0xc0000ea600, 0xc000c97940, {0x5575a2dd49f8, 0xc0006608d0}, {0x5575a2dd4fc8, 0xc000c96400}, {0x5575a2dd4998, 0xc000122630}, 0x27, 0x1590700)
    /usr/lib64/go/1.22/src/go/types/expr.go:800 +0x166
go/types.(*Checker).exprInternal(0xc0000ea600, 0x0, 0xc000c97940, {0x5575a2dd49f8, 0xc0006608d0}, {0x0, 0x0})
    /usr/lib64/go/1.22/src/go/types/expr.go:1416 +0x206
go/types.(*Checker).rawExpr(0xc0000ea600, 0x0, 0xc000c97940, {0x5575a2dd49f8?, 0xc0006608d0?}, {0x0?, 0x0?}, 0x0)
    /usr/lib64/go/1.22/src/go/types/expr.go:979 +0x19e
go/types.(*Checker).expr(0xc0000ea600, 0x5575a30f42e0?, 0xc000c97940, {0x5575a2dd49f8?, 0xc0006608d0?})
    /usr/lib64/go/1.22/src/go/types/expr.go:1513 +0x30
go/types.(*Checker).initVars(0xc0000ea600, {0xc000d2e660, 0x1, 0x6?}, {0xc000c94310, 0x5575a30f45e0?, 0xc000ca1f80?}, {0x5575a2dd4c98, 0xc0000a06e0})
    /usr/lib64/go/1.22/src/go/types/assignments.go:381 +0x60b
go/types.(*Checker).stmt(0xc0000ea600, 0x0, {0x5575a2dd4c98, 0xc0000a06e0})
    /usr/lib64/go/1.22/src/go/types/stmt.go:524 +0x1fc5
go/types.(*Checker).stmtList(0xc0000ea600, 0x0, {0xc000c94320?, 0x5575a2ad6c96?, 0x5?})
    /usr/lib64/go/1.22/src/go/types/stmt.go:121 +0x85
go/types.(*Checker).stmt(0xc0000ea600, 0x0, {0x5575a2dd4d28, 0xc000660930})
    /usr/lib64/go/1.22/src/go/types/stmt.go:562 +0x20f2
go/types.(*Checker).stmt(0xc0000ea600, 0x0, {0x5575a2dd4d58, 0xc000c96440})
    /usr/lib64/go/1.22/src/go/types/stmt.go:574 +0x3017
go/types.(*Checker).stmtList(0xc0000ea600, 0x0, {0xc0000bc300?, 0x0?, 0xc000191f10?})
    /usr/lib64/go/1.22/src/go/types/stmt.go:121 +0x85
go/types.(*Checker).funcBody(0xc0000ea600, 0x5575a2dd2dc8?, {0xc00049a690?, 0x5575a30f42e0?}, 0xc000c973c0, 0xc0006609f0, {0x0?, 0x0?})
    /usr/lib64/go/1.22/src/go/types/stmt.go:41 +0x331
go/types.(*Checker).funcDecl.func1()
    /usr/lib64/go/1.22/src/go/types/decl.go:852 +0x3a
go/types.(*Checker).processDelayed(0xc0000ea600, 0x0)
    /usr/lib64/go/1.22/src/go/types/check.go:467 +0x162
go/types.(*Checker).checkFiles(0xc0000ea600, {0xc000532d80, 0x4, 0x4})
    /usr/lib64/go/1.22/src/go/types/check.go:411 +0x1cc
go/types.(*Checker).Files(...)
    /usr/lib64/go/1.22/src/go/types/check.go:372
golang.org/x/tools/go/packages.(*loader).loadPackage(0xc00013e2a0, 0xc000311260)
    /home/abuild/rpmbuild/BUILD/mockery-2.40.1/vendor/golang.org/x/tools/go/packages/packages.go:1052 +0xa72
golang.org/x/tools/go/packages.(*loader).loadRecursive.func1()
    /home/abuild/rpmbuild/BUILD/mockery-2.40.1/vendor/golang.org/x/tools/go/packages/packages.go:851 +0x1a9
sync.(*Once).doSlow(0x0?, 0x0?)
    /usr/lib64/go/1.22/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
    /usr/lib64/go/1.22/src/sync/once.go:65
golang.org/x/tools/go/packages.(*loader).loadRecursive(0x0?, 0x0?)
    /home/abuild/rpmbuild/BUILD/mockery-2.40.1/vendor/golang.org/x/tools/go/packages/packages.go:839 +0x4a
golang.org/x/tools/go/packages.(*loader).refine.func2(0x0?)
    /home/abuild/rpmbuild/BUILD/mockery-2.40.1/vendor/golang.org/x/tools/go/packages/packages.go:774 +0x26
created by golang.org/x/tools/go/packages.(*loader).refine in goroutine 1
    /home/abuild/rpmbuild/BUILD/mockery-2.40.1/vendor/golang.org/x/tools/go/packages/packages.go:773 +0xccf

Mockery Version

2.40.1

Golang Version

1.22rc2 works with 1.21

Installation Method

Steps to Reproduce

  1. build with go1.22

Expected Behavior

not crashing

Actual Behavior

crashing

alfa-alex commented 4 months ago

I can reproduce this. :heavy_check_mark: Since this implies non-backwards-compatible behavior of the Go compiler, isn't this rather an issue for the Go project?

darix commented 4 months ago

I just wanted to make the project aware that there is an issue.

peczenyj commented 4 months ago

This issue is a blocker for me, I can't move to go 1.22 if the mockery panics and I understand it can be an issue that may be fixed in go 1.22.1 but someone must open an issue on google side

viktorasm commented 4 months ago

Posted a fix.

It's a bit of a blocker for us, we're using mockery without installing it in CI, via go run, so it gets coupled with the compiler version that CI uses. It's a convenient way for us to pin mockery version across dev machines and CI without relying on dockerized execution.

//go:generate go run github.com/vektra/mockery/v2@v2.40.1
ajorgensen commented 4 months ago

I can confirm that @viktorasm fix worked for me

mattavos commented 1 month ago

Fixed in mockery v2@2.40.2 (https://github.com/vektra/mockery/releases/tag/v2.40.2) specifically https://github.com/vektra/mockery/commit/f513d5d71a384ba7b0c46e8731321c0fada7881f