Skip to content

feat(parser): support *types.Alias, *types.Signature, *types.TypeParam (v0.5.0)#78

Merged
54m merged 6 commits into
mainfrom
feat/handle-alias-signature-typeparam
May 3, 2026
Merged

feat(parser): support *types.Alias, *types.Signature, *types.TypeParam (v0.5.0)#78
54m merged 6 commits into
mainfrom
feat/handle-alias-signature-typeparam

Conversation

@54m
Copy link
Copy Markdown
Member

@54m 54m commented May 3, 2026

Summary

Adds support for three previously panicking type kinds in the named-type switch:

  • *types.Alias (resolved via types.Unalias)
  • *types.Signature (falls back to Any{})
  • *types.TypeParam (falls back to Any{})

Also fixes the misleading panic message wording (unsupported named type:unsupported type:), bumps Go directive to 1.25.0, and updates CI tooling.

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 this parser did not have a case for *types.Alias, so any input that touched any (transitively) panicked with:

```
unsupported named type: *types.Alias
```

A consumer (api_gen v2.14.1 / obunsha-projects) reported a panic on a service whose interfaces transitively reference map[string]any.

Changes

Parser

  • Add *types.Alias case using types.Unalias. nil-guarded for incomplete aliases (godoc-documented possibility).
  • Add *types.Signature and *types.TypeParam cases. Both fall back to Any{} (no Function type added; scope creep avoided).
  • Rename panic message from unsupported named type: to unsupported type:.

Tooling

  • go directive: 1.22 → 1.25.0 (bumped via go get -u golang.org/x/tools@latest).
  • golang.org/x/tools: v0.23.0 → v0.44.0 to fix Go 1.26 build error.
  • CI go-version: 1.22 → 1.24 (for Go 1.24+ generic alias fixture).
  • CI workflow trigger branch: mastermain (was preventing CI from running on PRs).

Tests

  • New testdata/alias/{base/main.go,test.go} with 6 fixtures: map[string]any, []any, type UserID = string, func(int) error, Box[T] (generic struct), VecAny[T any] = []T (generic alias).
  • Asserts the post-resolution shapes (Nullable{Map/Array/...{Any{}}} and String/Number for named-basic aliases).

Docs

  • README: Behavior notes section covering newly supported types, migration guidance for panic→Any fallback, and Replacer idempotency caveat.

Breaking

  • go directive bumped to 1.25.0 (was 1.22). Users of go-easyparser must use Go 1.23 or later.

Notes (non-breaking, but worth knowing)

  • func(...) fields, generic type parameters, and type aliases used to panic. They now produce Any{} (or resolved type). If you relied on the panic for fail-fast validation, install a custom Replacer.
  • panic message wording changed (cosmetic).
  • When a *types.Alias is parsed, the user-supplied Replacer is invoked twice (once on the alias, once on the Unalias-resolved type via recursive parseType). Replacers should be idempotent.

Test plan

  • GODEBUG=gotypesalias=1 go test ./... -count=1 PASS
  • go vet ./... clean
  • go build ./... exit 0
  • New TestParser_Parse/alias subtests pass (6 fixtures)
  • Existing tests (success / recursive / conflict / replace) PASS

54m added 6 commits May 3, 2026 11:54
Go 1.23 made gotypesalias=1 the default, which causes type aliases
such as 'any' (alias for interface{}) to appear as *types.Alias in
go/types output. The parser's named-type switch did not have a case
for this and emitted 'unsupported named type: *types.Alias' for any
input that uses 'any', map[string]any, etc.

This commit:
- Adds *types.Alias case (resolved via types.Unalias, nil-guarded for
  incomplete aliases)
- Adds *types.Signature case (function types fall back to Any{})
- Adds *types.TypeParam case (generic type parameters fall back to Any{})
- Renames panic message 'unsupported named type:' to 'unsupported type:'
  (Map/Slice/etc. are not named types; the previous wording was misleading)
- Bumps go directive to 1.25.0 (toolchain upgrade via go get -u)
- Bumps golang.org/x/tools to v0.44.0 to fix Go 1.26 build error
- Bumps CI go-version to 1.24 (for Go 1.24+ generic alias testdata)
- Fixes CI workflow trigger branch from 'master' to 'main'
Adds testdata/alias/{base/main.go,test.go} covering:
- map[string]any (Map value alias resolved via Unalias)
- []any (Slice element alias)
- type UserID = string (named-basic alias, name elision verified)
- func(int) error field (Signature -> Any fallback)
- Box[T] generic struct (TypeParam -> Any fallback)
- type VecAny[T any] = []T (Go 1.24+ generic alias, Unalias -> []T -> Array{Number{}})

Asserts the expected post-resolution shapes (Nullable{Map/Array/...{Any{}}}
and String/Number for named-basic aliases) so future regressions in alias
handling are caught at testdata layer.

Note: generic alias fixture requires Go 1.24+ at test time.
…atibility

- Lower go directive 1.25.0 -> 1.23.0 (only types.Unalias requires 1.23+;
  keeping the floor low for downstream ecosystem)
- Add toolchain go1.25.0 directive
- Bump reviewdog/action-golangci-lint to @v2 to fix
  'unknown flag: --out-format' error (golangci-lint v2 dropped this flag)
x/tools v0.44.0 requires go >= 1.25.0. Lowering go directive below
that creates an inconsistency caught by 'go mod tidy' / CI build.
Drop the toolchain directive since it equals the go directive.
The previous reviewdog/action-golangci-lint@v2 invokes golangci-lint v2
with the removed --out-format flag, causing CI failure. Replace with
the same setup api_gen uses (golangci/golangci-lint-action@v7.0.1 with
golangci-lint v2.12.1 + .github/.golangci.yml config).

- Rename reviewdog.yaml -> linter.yml (api_gen naming convention)
- Switch from reviewdog/action-golangci-lint to golangci/golangci-lint-action@v7
- Rewrite .github/.golangci.yml from v1 format to v2 format
- Update local-prefixes to github.com/go-generalize/go-easyparser
- Remove api_gen-specific path exclusions (test/testdata_etc, internal/*)
- Move gofmt/goimports to formatters section (v2 requirement)
- Bump lint.yaml go-version to 1.25 to match go.mod
@54m 54m merged commit 4a814c4 into main May 3, 2026
3 checks passed
@54m 54m deleted the feat/handle-alias-signature-typeparam branch May 3, 2026 03: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.

1 participant