Skip to content

fix(parser): handle *types.Alias for Go 1.23+ type aliases#428

Merged
54m merged 2 commits into
masterfrom
fix/handle-types-alias
May 3, 2026
Merged

fix(parser): handle *types.Alias for Go 1.23+ type aliases#428
54m merged 2 commits into
masterfrom
fix/handle-types-alias

Conversation

@54m
Copy link
Copy Markdown
Member

@54m 54m commented May 3, 2026

Summary

Bumps go-easyparser to v0.5.0 which adds *types.Alias, *types.Signature, and *types.TypeParam support, fixing a panic for any consumer interface that uses any, map[string]any, function-type fields, or generic type parameters.

Background

Go 1.23 made gotypesalias=1 the default. This causes type aliases like any (an alias of interface{}) to appear as *types.Alias in go/types output. The named-type switch in go-easyparser did not have a case for *types.Alias, so any input that touched any (transitively) panicked with:

unsupported named type: *types.Alias

Fix

Verification

  • go build ./... exit 0
  • go vet ./... clean
  • GODEBUG=gotypesalias=1 go test ./... -count=1 -race PASS
  • Existing samples/{empty_root,standard} byte-identical after make gen_samples (version string only diff)
  • Reproduction (map[string]any) succeeds: code generation exits 0

Behavior note

After this fix, when a *types.Alias is encountered, Replacer is 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 recursive parseType call. 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 or Unalias)
  • panic message wording also fixed in v0.5.0 (unsupported named type: -> unsupported type:)

54m added 2 commits May 3, 2026 12:42
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/
@54m 54m merged commit 060c54e into master May 3, 2026
3 checks passed
@54m 54m deleted the fix/handle-types-alias branch May 3, 2026 03:51
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.

1 participant