feat: go 1.24 generic type aliases #261
Open
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.
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 interfacetype.
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 paramsfilled 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