Skip to content

fix(ast/transform): recognise method receiver param lists for type an…#59

Open
bbodi wants to merge 1 commit into
MadAppGang:mainfrom
bbodi:fix/transform-method-receiver-type-annotations
Open

fix(ast/transform): recognise method receiver param lists for type an…#59
bbodi wants to merge 1 commit into
MadAppGang:mainfrom
bbodi:fix/transform-method-receiver-type-annotations

Conversation

@bbodi

@bbodi bbodi commented May 17, 2026

Copy link
Copy Markdown

…notations

The token-walking transformer in TransformSource only entered the parameter-list context when it saw func name( or func(. For methods with a receiver, e.g. func (r *T) Foo(x: int), the second ( is preceded by IDENT RPAREN, which the previous logic treated as an arbitrary parenthesised expression. As a result the : in x: int was never converted into a space and the generated Go was invalid.

Detect the receiver form by walking backwards from the param list ( through a matching RPAREN ... LPAREN group with depth tracking, then checking that FUNC sits immediately before the receiver's (. The walk bails on ;, { or } so unrelated parenthesised expressions preceding a function call are not misclassified.

Added pkg/ast/transform_test.go with four cases (pointer receiver, value receiver + multiple params, body struct literal colons preserved, generic receiver type). Each parses the transformer output with go/parser so the assertion is exactly the property we care about: valid Go on the way out. Without this fix all four cases fail because the surviving : makes go/parser reject the param list.

…notations

The token-walking transformer in `TransformSource` only entered the
parameter-list context when it saw `func name(` or `func(`. For methods
with a receiver, e.g. `func (r *T) Foo(x: int)`, the second `(` is
preceded by `IDENT RPAREN`, which the previous logic treated as an
arbitrary parenthesised expression. As a result the `:` in `x: int` was
never converted into a space and the generated Go was invalid.

Detect the receiver form by walking backwards from the param list `(`
through a matching `RPAREN ... LPAREN` group with depth tracking, then
checking that `FUNC` sits immediately before the receiver's `(`. The
walk bails on `;`, `{` or `}` so unrelated parenthesised expressions
preceding a function call are not misclassified.

Added `pkg/ast/transform_test.go` with four cases (pointer receiver,
value receiver + multiple params, body struct literal colons preserved,
generic receiver type). Each parses the transformer output with
`go/parser` so the assertion is exactly the property we care about:
valid Go on the way out. Without this fix all four cases fail because
the surviving `:` makes go/parser reject the param list.
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