Skip to content

Go: add StatementExpression, fix variadic params, remove receiver overrides#7261

Merged
jkschneider merged 2 commits intomainfrom
jkschneider/go-receiver-overrides
Apr 2, 2026
Merged

Go: add StatementExpression, fix variadic params, remove receiver overrides#7261
jkschneider merged 2 commits intomainfrom
jkschneider/go-receiver-overrides

Conversation

@jkschneider
Copy link
Copy Markdown
Member

@jkschneider jkschneider commented Apr 2, 2026

Summary

Replaces the receiver overrides from #7258 with proper parser-level fixes:

Go.StatementExpression (new LST element): Wraps MethodDeclaration in expression contexts, following the same pattern as Cs.StatementExpression in rewrite-csharp. Go function literals (func(x int) int { return x }) are parsed as MethodDeclaration (a Statement) but appear in returns, assignments, and call arguments which require Expression.

Variadic parameter fix: Detect ...T in mapFieldListAsParams, store the ... prefix in VariableDeclarations.Varargs, and pass only the element type through mapTypeExpr. Previously ...T was mapped as Unary{Spread, T} in the TypeExpr field, violating the TypeTree constraint.

RPC parse input order: Check text-based inputs before file-path inputs so inline source code (from integration tests) isn't mistakenly treated as a file path.

Reverts #7258 receiver overrides — the proper fix is at the parser/sender level, not in the receiver.

Test plan

  • 8 new integration tests (pointer receivers, func literal return, deref, pointer slices, map pointer values, func type decls, nested func literals, variadic pointer params)
  • 51 of 52 integration tests pass (goroutineAndDefer fails — directly-invoked func literal padding mismatch, pre-existing edge case)

@github-project-automation github-project-automation Bot moved this to In Progress in OpenRewrite Apr 2, 2026
@jkschneider jkschneider marked this pull request as draft April 2, 2026 20:10
…d parse input order

Add Go.StatementExpression (both Java and Go sides) to wrap
MethodDeclaration in expression contexts, following the same pattern
as Cs.StatementExpression in rewrite-csharp. Func literals like
`func(x int) int { return x }` are parsed as MethodDeclaration (a
Statement) but need to appear in returns, assignments, and call args.

Fix variadic parameter handling: detect `...T` in mapFieldListAsParams,
store the `...` prefix in VariableDeclarations.Varargs, and pass only
the element type through mapTypeExpr. Previously `...T` was mapped as
Unary{Spread, T} in the TypeExpr field, which violated the TypeTree
constraint.

Fix RPC parse input order: check Text before Path/SourcePath so text-
based inputs (from integration tests) aren't mistakenly treated as
file paths.

Add 8 integration tests. 51 of 52 pass (goroutineAndDefer fails due
to directly-invoked func literal `go func(){}()` padding mismatch).
@jkschneider jkschneider force-pushed the jkschneider/go-receiver-overrides branch from 934ca1f to 39bea46 Compare April 2, 2026 20:25
@jkschneider jkschneider changed the title Go: add receiver overrides, integ tests, and fix RPC parse input order Go: add StatementExpression, fix variadic params, remove receiver overrides Apr 2, 2026
@jkschneider jkschneider marked this pull request as ready for review April 2, 2026 20:31
@jkschneider jkschneider merged commit d8adf51 into main Apr 2, 2026
1 check passed
@jkschneider jkschneider deleted the jkschneider/go-receiver-overrides branch April 2, 2026 20:31
@github-project-automation github-project-automation Bot moved this from In Progress to Done in OpenRewrite Apr 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant