feat(parser): support *types.Alias, *types.Signature, *types.TypeParam (v0.5.0)#78
Merged
Merged
Conversation
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
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
Adds support for three previously panicking type kinds in the named-type switch:
*types.Alias(resolved viatypes.Unalias)*types.Signature(falls back toAny{})*types.TypeParam(falls back toAny{})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=1the default. This causes type aliases likeany(an alias ofinterface{}) to appear as*types.Aliasingo/typesoutput. The named-type switch in this parser did not have a case for*types.Alias, so any input that touchedany(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
*types.Aliascase usingtypes.Unalias. nil-guarded for incomplete aliases (godoc-documented possibility).*types.Signatureand*types.TypeParamcases. Both fall back toAny{}(noFunctiontype added; scope creep avoided).unsupported named type:tounsupported type:.Tooling
godirective: 1.22 → 1.25.0 (bumped viago get -u golang.org/x/tools@latest).golang.org/x/tools: v0.23.0 → v0.44.0 to fix Go 1.26 build error.go-version: 1.22 → 1.24 (for Go 1.24+ generic alias fixture).master→main(was preventing CI from running on PRs).Tests
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).Nullable{Map/Array/...{Any{}}}andString/Numberfor named-basic aliases).Docs
Breaking
godirective 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 produceAny{}(or resolved type). If you relied on the panic for fail-fast validation, install a customReplacer.*types.Aliasis parsed, the user-suppliedReplaceris invoked twice (once on the alias, once on the Unalias-resolved type via recursiveparseType). Replacers should be idempotent.Test plan
GODEBUG=gotypesalias=1 go test ./... -count=1PASSgo vet ./...cleango build ./...exit 0TestParser_Parse/aliassubtests pass (6 fixtures)