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

Go 1.24 compatibility / package "context" without types was imported error #914

Closed
mikeauclair opened this issue Feb 11, 2025 · 9 comments · Fixed by #915
Closed

Go 1.24 compatibility / package "context" without types was imported error #914

mikeauclair opened this issue Feb 11, 2025 · 9 comments · Fixed by #915

Comments

@mikeauclair
Copy link

mikeauclair commented Feb 11, 2025

Seeing an error generating mocks with Go 1.24.0

2025/02/11 20:30:02 internal error: package "context" without types was imported from "<snipped>/client"

where the import is more-or-less just

package client

import (
  "context"
)

It looks like this has been a common issue in the past with new Go versions, and running through the cache clearing steps referred to in https://vektra.github.io/mockery/v2.35/notes/#internal-error-package-without-types-was-imported didn't appear to help so I figured I'd flag this in case it's an actual issue w/ 1.24.0

Thanks!

@firefart
Copy link

Having the same issue with go 1.24

@LandonTClipp
Copy link
Collaborator

LandonTClipp commented Feb 11, 2025

Thanks for the report. I'll have to look into this, usually these problems are environmental and involve stale cached packages, but since you said you already cleaned the cache and are still encountering the problems, there might be something novel going on.

Can you provide more details on your running environment:

  1. $ go version
    go version go1.23.5 darwin/arm64
    
  2. uname -a

This project also does not yet officially support 1.24 as you can see the go.mod file is at 1.23 and 1.24 is not in the testing matrix yet. I just need to spend some time to bringing it up to spec.

@firefart
Copy link

Sure

go version
go version go1.24.0 linux/amd64
uname -a
Linux zoidberg 5.15.167.4-microsoft-standard-WSL2 #1 SMP Tue Nov 5 00:21:55 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

Failure is also reproducible on github actions when running mockery

@mikeauclair
Copy link
Author

As requested:

$ go version
go version go1.24.0 linux/amd64
$ uname -a
Linux <hostname> 6.8.0-1021-aws #23-Ubuntu SMP Mon Dec  9 23:59:34 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux

(also occurring in our self-hosted GHA runners on arm64 / debian 22.04)

This project also does not yet official support 1.24 as you can see the go.mod file is at 1.23 and 1.24 is not in the testing matrix yet. I just need to spend some time to bringing it up to spec.

Totally understood, and thanks!

@LandonTClipp
Copy link
Collaborator

I reproduced the problem in CI: https://github.com/vektra/mockery/actions/runs/13278535376/job/37072470870?pr=915

Added support for 1.24 in #915. You can see after I add 1.24 in go.mod, the type errors go away.

I don't know exactly why this happens, but the Go language introduced generic constraints on type aliases in golang/go#46477, which I believe will cause the typing information as compiled to be incompatible with older versions. This shouldn't happen because ostensibly the Go compiler is capable of handling cases like this, and this is a clear backwards incompatibility (assuming this project is not actually doing anything wrong).

If anyone could help me figure out why exactly this happens and how to prevent it in future releases, I'd be eternally grateful.

@LandonTClipp
Copy link
Collaborator

Interestingly, I cannot reproduce this on my local env:

[ 12:00AM ]  [ landon@A02257:/tmp/test ]
 $ /tmp/go/bin/go version
go version go1.24.0 darwin/arm64
[ 12:00AM ]  [ landon@A02257:/tmp/test ]
 $ /tmp/go/bin/go run github.com/vektra/mockery/[email protected]
12 Feb 25 00:00 CST INF Starting mockery dry-run=false version=v2.52.1
12 Feb 25 00:00 CST INF Using config: /tmp/test/.mockery.yml dry-run=false version=v2.52.1
12 Feb 25 00:00 CST INF done loading, visiting interface nodes dry-run=false version=v2.52.1
12 Feb 25 00:00 CST INF generating mocks for interface dry-run=false interface=Foo qualified-name=test version=v2.52.1
12 Feb 25 00:00 CST INF writing to file dry-run=false file=mocks/test/mock_Foo.go interface=Foo qualified-name=test version=v2.52.1
12 Feb 25 00:00 CST WRN DEPRECATION: resolve-type-alias will be permanently set to False in v3. Please modify your config to set the parameter to False. deprecation-name=resolve-type-alias url=https://vektra.github.io/mockery/v2.52/deprecations/#resolve-type-alias version=v2.52.1
12 Feb 25 00:00 CST WRN DEPRECATION: issue-845-fix must be set to True to remove this warning. Visit the link for more details. deprecation-name=issue-845-fix url=https://vektra.github.io/mockery/v2.52/deprecations/#issue-845-fix version=v2.52.1

It compiles just fine. Anyway, let me know if v2.52.2 fixes the issue for you.

@LandonTClipp LandonTClipp reopened this Feb 12, 2025
@LandonTClipp
Copy link
Collaborator

LandonTClipp commented Feb 12, 2025

Oops, I got the right answer, but for the wrong reason. The problem appears to have been resolved by upgrading the golang.org/x/tools version, not by bumping go.mod. That makes sense because we use the golang.org/x/tools/go/packages package to parse type information, so updates to the typing system would require updates to that package.

#535

@firefart
Copy link

Thanks, the update fixed it. The issue can now be closed

@mikeauclair
Copy link
Author

Thanks for the expedient update here!

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

Successfully merging a pull request may close this issue.

3 participants