Skip to content

GROOVY-12144: Fix AstNodeToScriptAdapter decompiler rendering fidelity (GROOVY_4_0_X backport)#2685

Merged
daniellansun merged 1 commit into
apache:GROOVY_4_0_Xfrom
leonard84:GROOVY-12144-backport-GROOVY_4_0_X
Jul 11, 2026
Merged

GROOVY-12144: Fix AstNodeToScriptAdapter decompiler rendering fidelity (GROOVY_4_0_X backport)#2685
daniellansun merged 1 commit into
apache:GROOVY_4_0_Xfrom
leonard84:GROOVY-12144-backport-GROOVY_4_0_X

Conversation

@leonard84

Copy link
Copy Markdown
Contributor

This backports the eight decompiler-fidelity fixes from master (#2682, commit 4b27025962) to GROOVY_4_0_X. AstNodeToScriptVisitor rendered several constructs so they did not round-trip; each fix is localized to one visitor method:

  1. Nested generic type arguments dropped (Map<String, List<Integer>>Map<String, List>) — visitGenerics recurses into concrete args.
  2. Range bound exclusions dropped — visitRangeExpression.
  3. Elvis rendered as a duplicated ternary (c ?: dc ? c : d, evaluating c twice) — visitShortTernaryExpression emits ?:.
  4. Attribute access lost the at-sign (obj.@fobj.f) — visitPropertyExpression emits .@ for an AttributeExpression.
  5. Explicit zero-arg closures lost the arrow ({ -> ... }{ ... }) — visitClosureExpression distinguishes a null parameter list from Parameter.EMPTY_ARRAY.
  6. Safe index access lost safe navigation (list?[0]list[0]) — visitBinaryExpression.
  7. Numeric literal type suffixes dropped (42L/2.5f/3.5d/10G) — visitConstantExpression re-appends L/F/D/G.
  8. Explicit method-call type arguments dropped (Collections.<String>emptyList()) — visitMethodCallExpression.

One regression test per defect (GroovyTestCase style, matching the existing test class). Existing tests reconciled to the corrected output: testTernaryOperaters (elvis), testGenericsInMethods (nested generics now preserved), testLogAnnotation (@Log's Level.FINE is an AttributeExpression, now renders Level.@FINE).

Branch adaptation (fix 6): on 4.0 the safe-index operator carries its own ?[ operation text (the file has drifted from master), so visitBinaryExpression'"'"'s subscript detection was widened to recognise ?[ and emit ?[/[ per isSafe(). Verified to round-trip.

Tests: AstNodeToScriptAdapterTest 71/71 (forced recompile+run). Whole-module has 3 pre-existing SwingBuilderConsoleTest GUI failures unrelated to this change (confirmed against the untouched baseline).

Master PR: #2682


🤖 Prepared with Claude Code (Opus 4.8) on behalf of @leonard84.

GROOVY_4_0_X backport of master commit 4b27025. AstNodeToScriptVisitor
rendered several constructs incorrectly, producing source that did not
round-trip. Applies the eight independent visitor-method fixes and their
regression tests (nested generics, exclusive range bounds, Elvis, attribute
access, explicit zero-arg closure arrow, safe index access, numeric literal
suffixes, explicit method-call type arguments).

Assisted-by: Claude Code (Opus 4.8)
@daniellansun daniellansun merged commit 59683d2 into apache:GROOVY_4_0_X Jul 11, 2026
21 checks passed
@daniellansun

Copy link
Copy Markdown
Contributor

Merged. Thanks.

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.

2 participants