-
Notifications
You must be signed in to change notification settings - Fork 411
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
Fix Go 1.23 types.Alias handling #808
Conversation
@@ -508,6 +508,8 @@ func (g *Generator) renderType(ctx context.Context, typ types.Type) string { | |||
args = append(args, g.renderType(ctx, arg)) | |||
} | |||
return fmt.Sprintf("%s[%s]", name, strings.Join(args, ",")) | |||
case *types.Alias: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually surprised that CI/CD is not failing in the go1.21 test. This didn't exist until 1.22 so technically this won't compile if someone tries to build with 1.21.
If I'm understanding that correctly, we will need to make sure people understand. But I'd also like to figure out why CICD didn't fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, go will download at least 1.22 because of our go.mod
$ /opt/homebrew/opt/[email protected]/bin/go version
go: downloading go1.22.0 (darwin/arm64)
go version go1.22.0 darwin/arm64
Also 1.21 is not supported anymore anyways, so we can probably remove it from the matrix and figure out how to get 1.23 to work in the test matrix.
Warning: [email protected] has been deprecated because it is not supported upstream! It will be disabled on 2025-08-16.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a CI test with go 1.23 enabled, but it requires the lastest golangci-lint, but installing it forces the library's go.mod to go 1.23.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@RangelReale we need to upgrade mockery to include 1.23 in the test matrix. I also think we'll need to bump go.mod
to 1.23 as well considering that we'll be supporting type.Alias
now.
Some of the depdencies like golangci-lint and go-task need to be updated as well.
Unfortunately it seems like golangci-lint updates cause a few new linter errors:
$ go run github.com/go-task/task/v3/cmd/task test.ci
task: [lint] go run github.com/golangci/golangci-lint/cmd/golangci-lint run
task: [fmt] go fmt ./...
go: downloading github.com/prometheus/client_model v0.5.0
WARN The linter 'exportloopref' is deprecated (since v1.60.2) due to: Since Go1.22 (loopvar) this linter is no longer relevant. Replaced by copyloopvar.
pkg/logging/logging.go:77:25: G115: integer overflow conversion uintptr -> int (gosec)
if !term.IsTerminal(int(out.Fd())) || os.Getenv("TERM") == "dumb" {
^
pkg/generator.go:440:11: printf: non-constant format string in call to (*github.com/vektra/mockery/v2/pkg.Generator).printf (govet)
g.printf(prologue)
^
pkg/config/config.go:191:33: printf: non-constant format string in call to fmt.Errorf (govet)
return []string{}, fmt.Errorf(msg)
^
pkg/config/config.go:398:20: printf: non-constant format string in call to (*github.com/rs/zerolog.Event).Msgf (govet)
log.Error().Msgf(msgString)
^
pkg/config/config.go:798:22: printf: non-constant format string in call to fmt.Errorf (govet)
return fmt.Errorf(msg)
Let me know if you would like to tackle the upgrades first. Once that is merged, you'll want to rebase this branch off of it to ensure the go1.23 changes work as expected. If you don't have time, perhaps I can look into the upgrades.
Another comment, I'm kind of doubting my mental model of how Go handles go.mod. It seems to be that if we specify |
I thought that too, but no, surprisingly the //go:build tag is for the version that is being used for compilation, not the one that is in the go.mod files, I had to do some hacks because of it. |
I actually upgraded it, but reverted once I say that it changed go.mod, it's not too much things, I can do it again. But will we bump the go.mod version to 1.23? Isn't it too early? |
Maybe so. I don't actually know the right thing to do. AFAIK go.mod I would like if someone could educate me on the right way to do it. Much of how Go handles this is still mysterious to me. |
I don't know it completely also, I know that |
Upgraded golangci-lint and replace go 1.21 with go 1.23 in tests. |
In the end it didn't change the go.mod in the root folder, so we should be good. |
Wonderful! Looks great. I will give final approval and merge/deploy in a few days. |
I looked more into this to make sure we're doing the right thing. Some notes:
|
I did some other tests with a separate repo using So, the only way to ensure aliases being generated without GODEBUG is making go 1.23 a requirement. In my case I am using |
Well Go 1.23.1 was released and we upgraded our repo to it. But I see you created a new major version, maybe you would want to do this in that version? |
I'm going through an airport here shortly so I will have time to get to this. I think we can upgrade it in the current major version since AFAIK it is backwards compatible with the user's installed Go version. |
I made a few changes and merged. Thanks @RangelReale for the great work! I will do a release once I get better internet. Somehow I am able to browse the web on an airplane but I can't tag a git repo. Who knows why. |
Hey, looks like this change results in a circular dependency if mock is used in the package where it's defined: // ./p/iface.go
package p
type T = int
//go:generate mockery --quiet --name I
type I interface{ F(T) }
// this generates ./p/mocks/I.go
package mocks
import "p"
func (_m *I) F(_a0 p.T) {
...
// ./p/i_test.go
import "p/mocks" // fails because of circular dependency Is it possible to use target types instead of aliases in go 1.23? |
Description
Support the new
types.Alias
type, both in Go 1.22 and Go 1.23.If
types.Alias
is supported,replace-types
will not match the new type, so it is safe to leave it as it is until we stop supporting Go 1.22.Go 1.22 includes a
types.Alias
type to ease the migration, but by default is is never returned unlessgotypesalias=1
. It has more fields in Go 1.23, so build constraints had to be used to cover these cases.Type of change
Version of Go used when building/testing:
How Has This Been Tested?
Added new tests.
Checklist