Go: override Java receiver visitors for Go-specific type mismatches#7258
Merged
jkschneider merged 1 commit intomainfrom Apr 2, 2026
Merged
Go: override Java receiver visitors for Go-specific type mismatches#7258jkschneider merged 1 commit intomainfrom
jkschneider merged 1 commit intomainfrom
Conversation
Go's AST uses nodes in positions where Java's model requires stricter types. For example, Go pointer types are J.Unary (not TypeTree), function literals are J.MethodDeclaration (not Expression), and Go primitives may arrive as JavaType.Class (not JavaType.Primitive). Add GolangReceiverDelegate overrides for visitArrayType, visitLiteral, visitMethodDeclaration, visitReturn, and visitVariableDeclarations. Each reads the RPC value without the Java-side type constraint, then uses the typed setter when possible or reflection when the Go node doesn't satisfy the Java interface. Tested against 15 popular Go repos (1,235 .go files total): 0 Go parse errors (100% success rate).
2 tasks
jkschneider
added a commit
that referenced
this pull request
Apr 2, 2026
…rrides (#7261) * Revert "Go: override Java receiver visitors for Go-specific type mismatches (#7258)" This reverts commit 8174845. * Go: add StatementExpression for func literals, fix variadic params and 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).
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
Add
GolangReceiverDelegateoverrides for 5 Java receiver visitor methods that fail when deserializing Go ASTs:visitArrayType— Go slice element types like[]*TproduceJ.Unary, notTypeTreevisitLiteral— Go primitive literals arrive asJavaType.Class, notJavaType.PrimitivevisitMethodDeclaration— Go return types can be pointer/slice types that don't implementTypeTreevisitReturn— Go function literals in return position areJ.MethodDeclaration, notExpressionvisitVariableDeclarations— Go pointer/slice/map types in type position don't implementTypeTreeEach override reads the RPC value without the Java-side type constraint, then uses the typed setter when possible or reflection when the Go node doesn't satisfy the Java interface.
Test plan