issue #298 - go 1.23 go/types alias change #301
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
From the go 1.23 changelog:
Previously, the AST node for an alias-typed value would point directly at the underlying type, and counterfeiter would consequently see the underlying type and load the correct package(s) for that type.
In go 1.23 or newer, when processing such a node, we get the unrecognized
*types.Alias
type, and fall through to thedefault
case, which prints an error and moves on. Then, when it comes time to render that type in (for instance) a method signature, it is rendered as a simple name, since the package alias was never added to theImports
struct.This change ensures that we load the appropriate package for each alias type. This resolves a bug introduced by go 1.23, and also slightly changes the behavior from previous versions of counterfeiter, which implicitly resolved alias types and replaced them with the RHS (right-hand side) of the alias assignment. If we wanted to preserve that behavior, I believe we could instead use:
However, I think using the actual alias (mimicking the interface being mocked) is preferable to resolving the alias.