fix(ast/transform): recognise method receiver param lists for type an…#59
Open
bbodi wants to merge 1 commit into
Open
fix(ast/transform): recognise method receiver param lists for type an…#59bbodi wants to merge 1 commit into
bbodi wants to merge 1 commit into
Conversation
…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
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.
…notations
The token-walking transformer in
TransformSourceonly entered the parameter-list context when it sawfunc name(orfunc(. For methods with a receiver, e.g.func (r *T) Foo(x: int), the second(is preceded byIDENT RPAREN, which the previous logic treated as an arbitrary parenthesised expression. As a result the:inx: intwas never converted into a space and the generated Go was invalid.Detect the receiver form by walking backwards from the param list
(through a matchingRPAREN ... LPARENgroup with depth tracking, then checking thatFUNCsits 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.gowith four cases (pointer receiver, value receiver + multiple params, body struct literal colons preserved, generic receiver type). Each parses the transformer output withgo/parserso 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.