fix(parser): handle *types.Alias for Go 1.23+ type aliases#428
Merged
Conversation
Go 1.23 makes gotypesalias=1 the default, causing type aliases such as
any (alias for interface{}) to appear as *types.Alias in go/types.
go-easyparser v0.5.0 handles *types.Alias, *types.Signature, and
*types.TypeParam, fixing the panic in api_gen.
- go.mod
- go.sum
Adds a minimal reproduction case under pkg/server/testdir/alias_repro/ that exercises map[string]any (which triggers *types.Alias in Go 1.23+). The generated server/ directory is committed as a static fixture so the regression is detected if go-easyparser ever drops the *types.Alias case again. This testdir is intentionally NOT added to make gen_samples to avoid false-positive diffs from version-string drift. - pkg/server/server_test.go - pkg/server/testdir/alias_repro/interfaces/get.go - pkg/server/testdir/alias_repro/server/
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.
Summary
Bumps
go-easyparserto v0.5.0 which adds*types.Alias,*types.Signature, and*types.TypeParamsupport, fixing a panic for any consumer interface that usesany,map[string]any, function-type fields, or generic type parameters.Background
Go 1.23 made
gotypesalias=1the default. This causes type aliases likeany(an alias ofinterface{}) to appear as*types.Aliasingo/typesoutput. The named-type switch ingo-easyparserdid not have a case for*types.Alias, so any input that touchedany(transitively) panicked with:Fix
go-easyparser: v0.3.3 -> v0.5.0 (https://github.com/go-generalize/go-easyparser/releases/tag/v0.5.0)pkg/server/testdir/alias_repro/Verification
go build ./...exit 0go vet ./...cleanGODEBUG=gotypesalias=1 go test ./... -count=1 -racePASSsamples/{empty_root,standard}byte-identical aftermake gen_samples(version string only diff)map[string]any) succeeds: code generation exits 0Behavior note
After this fix, when a
*types.Aliasis encountered,Replaceris invoked twice: once on the original alias type (returns nil because the api_gen replacer only matches*types.Named), then again on the Unalias-resolved type via the recursiveparseTypecall. This is harmless for api_gen but downstream consumers of go-easyparser using alias-name-based replacers should be aware.Notes
*types.Signature,*types.TypeParam, generic type aliases (Go 1.24+) are also handled in v0.5.0 (Any{}fallback orUnalias)unsupported named type:->unsupported type:)