Skip to content

fix(ast/enum_parser): allow arbitrary nesting of '*' and '[]' in variant field types#61

Open
bbodi wants to merge 1 commit into
MadAppGang:mainfrom
bbodi:fix/enum-parser-type-prefix-nesting
Open

fix(ast/enum_parser): allow arbitrary nesting of '*' and '[]' in variant field types#61
bbodi wants to merge 1 commit into
MadAppGang:mainfrom
bbodi:fix/enum-parser-type-prefix-nesting

Conversation

@bbodi

@bbodi bbodi commented May 18, 2026

Copy link
Copy Markdown

Summary

EnumParser.parseTypeExpr was conservative about how it parsed type prefixes on struct- and tuple-variant fields. It accepted any number of * prefixes followed by at most one [], and only in the order <pointers><slice><name>. So:

Type Before After
*T
**T
*[]T
[]T
[]*T
[][]T
[][]*T

When the parser hit a rejected prefix, the failure surfaced two phases later as a confusing

parse error: expected declaration, found enum

pointing at the enum's opening line — making the real cause hard to spot.

The fix replaces the two ad-hoc loops with a single loop that consumes * and [] in any order and any count, matching what the rest of the Dingo pipeline already accepts for ordinary field types.

Test plan

  • go test ./pkg/ast/... (new TestEnumParser_TypePrefixes covers 9 prefix shapes for struct variants, TestEnumParser_TupleTypePrefixes covers 2 for tuple variants)
  • go test ./... (full suite stays green; no other parser/codegen regression)
  • End-to-end TransformSource regression for the previously failing []*Name field plus a multi-line variant body

🤖 Generated with Claude Code

…ant field types

The enum parser's parseTypeExpr accepted any number of '*' prefixes, but only
a single trailing '[]', and only in the order `<pointers><slice><name>`. Field
declarations such as `[]*Foo`, `[][]Foo`, or `[][]*Foo` therefore tripped the
parser, which surfaced downstream as a confusing
"parse error: ... expected declaration, found enum" message at the enum's
opening line.

Replace the two ad-hoc loops with a single loop that consumes '*' and '[]'
tokens in any order and any count, matching what the rest of the pipeline
already accepts for ordinary field types.

Tests cover plain, pointer (*T, **T), slice ([]T, [][]T), mixed (*[]T, []*T,
[][]*T), generic slice ([]int) prefixes for both struct-style and tuple-style
variants, plus end-to-end regressions through TransformSource for the
previously failing `[]*Name` and multi-line variant bodies.
bbodi added a commit to bbodi/dingo that referenced this pull request May 18, 2026
…g#62 into fork main

Combines all four currently open pull requests against MadAppGang/dingo into
the local fork's main so downstream work (e.g. the nodes.go cascade fix) can
build on top of all of them without one-by-one branch juggling. The
upstream PRs remain unaffected because their base branch is MadAppGang/dingo:main,
not bbodi/dingo:main.

Included:
  MadAppGang#59 fix(ast/transform): recognise method receiver param lists for type annotations
  MadAppGang#60 test(tokenizer): cover ENUM and GUARD keywords at both surfaces
  MadAppGang#61 fix(ast/enum_parser): allow arbitrary nesting of '*' and '[]' in variant field types
  MadAppGang#62 feat(feature): add Validator plugin extension and character-level pre-transform phase
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