Repository navigation
fix: generate Reset for generic structs - #12
Merged
Merged
Conversation
The generator panicked on a generic struct (go/types cannot size a type parameter), and the template would have declared the receiver without its type parameters. Reset now names them (func (r *Pair[K, V]) Reset()), resets a type-parameter field to *new(T), and the cost model sizes each type parameter as a pointer. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e parameters
A type-parameter field whose constraint lets only pointers in and has
Reset (P interface{ *T; Reset() }) is now kept and reset when not nil,
like any pointer with Reset. call= on a type parameter that is not only
pointers generated r.F != nil, which does not compile; it now calls the
method without the check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The generator panicked on a generic struct: go/types cannot size a type parameter, and the cost model asks for the struct's size. The template would also have declared the receiver without its type parameters.
func (r *Pair[K, V]) Reset(),*r = Pair[K, V]{}.*new(T), even when its constraint hasReset(), since the call could not be guarded against nil.Reset()(P interface{ *T; Reset() }, or a union of pointers) is kept and reset when not nil, like any pointer withReset().call=on a type parameter that is not only pointers generatedr.F != nil, which does not compile; the method is now called without the check.r(the receiver) is reported as an error.Tests:
TestGenericgenerates Reset for four generic types in a throwaway module and runs go vet and go test there;TestGenericReceiverName.