Skip to content

feat: go 1.24 generic type aliases #261

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hpidcock
Copy link

In Go 1.24, generic type aliases are added to the language. These are useful for
aliases of a generic type with some of the type params filled out without creating a
new type. See https://tip.golang.org/ref/spec#Alias_declarations

This aims to implement #260 as well as fix #217 by using the type parameters of
the root/first type alias. If the root type alias is not generic, then we can just use
the types.Named of the interface, as this is the instantiation of a generic interface
type.

When we encounter a root/first type alias that is generic, we need to ensure the
same type params are used for the mock implementation. This is because the
types.Named for the generic interface is a instantiation with the type params
filled out (i.e. type args). Some of these type args may be generic types, instantiated
based on the type params of one or many generic type aliases chained together.
The types package has resolved these for us, we just need to use the type params
from the root/first generic type alias.

Implements #260
Fixes #217

@hpidcock hpidcock force-pushed the fix-generic-alias branch from f44b3d2 to 0a69a9e Compare June 24, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New package mode fails to generate proper mock for type alias for interface with type params
1 participant