Skip to content

GROOVY-12715: let a cast apply to await and to an async closure - #3248

Merged
daniellansun merged 3 commits into
apache:masterfrom
codeconsole:fix/groovy-12715-cast-await
Nov 18, 2026
Merged

daniellansun merged 3 commits into
apache:masterfrom
codeconsole:fix/groovy-12715-cast-await

Conversation

@codeconsole

Copy link
Copy Markdown
Contributor

await and async have their own alternatives in the expression rule (awaitExprAlt, asyncClosureExprAlt), but the operand of a cast is parsed by castOperandExpression, which listed only another cast, a postfixExpression and the unary operators. After a cast the two words therefore fell back to being identifiers: (BigDecimal) await(price) was a call to a method named await with one argument and (Awaitable<Integer>) async { 7 } a call to a method named async with a closure. At script level that is a MissingMethodException; inside an async task the failure is swallowed by the task nobody awaits, and the code awaiting the task's result hangs (the issue has the three reproducers; the parenthesised forms (int) (await t) and -(await t) were fine).

castOperandExpression gains the two alternatives, with the same labels; the rule declares baseContext = expression, so they produce the same contexts and AstBuilder.visitAwaitExprAlt and visitAsyncClosureExprAlt apply unchanged.

Tests: AsyncAwaitTest gains a cast applied to await with one and with several arguments, the same inside an async task that binds a DataflowVariable (the shape that hung), and a cast applied to an async closure. On JDK 21 AsyncAwaitTest (277 tests) and ParserPositiveSyntaxTest pass; ParserNegativeSyntaxTest shows only the two failures master has since GEP-19 landed (#3247 fixes those).

Found by the eval harness of a Groovy-for-agents project: Claude Opus 5.5 wrote the cast form in every statically typed answer to a dataflow task, and each run timed out. Candidate for GROOVY_6_0_X as well.

await and async have their own alternatives in the expression rule, but the
operand of a cast is parsed by castOperandExpression, which listed only a
cast, a postfixExpression and the unary operators, so after a cast the two
words fell back to identifiers: (BigDecimal) await(price) was a call to a
method named await and (Awaitable<Integer>) async { 7 } a call to a method
named async. At script level that is a MissingMethodException; inside an
async task the failure is swallowed and the code awaiting the task's result
hangs. castOperandExpression gains the asyncClosureExprAlt and awaitExprAlt
alternatives; the rule shares expression's contexts, so AstBuilder handles
them unchanged.

Tests in AsyncAwaitTest: a cast applied to await (single and multiple
arguments), inside an async task that binds a dataflow variable, and to an
async closure.
@codecov-commenter

codecov-commenter commented Nov 6, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.4160%. Comparing base (d1710f8) to head (85443e9).
⚠️ Report is 40 commits behind head on master.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                 @@
##               master      #3248        +/-   ##
==================================================
+ Coverage     74.2207%   74.4160%   +0.1953%     
- Complexity      43914      44383       +469     
==================================================
  Files            1692       1699         +7     
  Lines          149911     151067      +1156     
  Branches        28466      28790       +324     
==================================================
+ Hits           111265     112418      +1153     
+ Misses          28444      28381        -63     
- Partials        10202      10268        +66     

see 62 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@daniellansun daniellansun left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for GROOVY-12715.

castOperandExpression omitted the async / await alternatives that expression already has, so after a cast those words fell back to method names — (BigDecimal) await(price) and (Awaitable<Integer>) async { … } were wrong AST, and the hanging form inside an async task is a real trap. Adding the same labelled alternatives (with baseContext = expression) so existing AstBuilder visitors apply is the minimal, correct fix.

Tests cover cast-on-await (one and several args), the DataflowVariable shape that hung, and cast-on-async-closure. Parser-only; low risk.

CI fully green.

@testlens-app

testlens-app Bot commented Nov 8, 2026 •

Copy link
Copy Markdown

✅ All tests passed ✅

🏷️ Commit: 85443e9
▶️ Tests: 11558 executed
⚪️ Checks: 26/26 completed


Learn more about TestLens at testlens.app/docs.

@daniellansun
daniellansun merged commit cb6cd05 into apache:master Nov 18, 2026
36 of 54 checks passed
daniellansun pushed a commit that referenced this pull request Nov 18, 2026
* GROOVY-12715: let a cast apply to await and to an async closure

await and async have their own alternatives in the expression rule, but the
operand of a cast is parsed by castOperandExpression, which listed only a
cast, a postfixExpression and the unary operators, so after a cast the two
words fell back to identifiers: (BigDecimal) await(price) was a call to a
method named await and (Awaitable<Integer>) async { 7 } a call to a method
named async. At script level that is a MissingMethodException; inside an
async task the failure is swallowed and the code awaiting the task's result
hangs. castOperandExpression gains the asyncClosureExprAlt and awaitExprAlt
alternatives; the rule shares expression's contexts, so AstBuilder handles
them unchanged.

Tests in AsyncAwaitTest: a cast applied to await (single and multiple
arguments), inside an async task that binds a dataflow variable, and to an
async closure.

* GROOVY-12715: bound the await in the cast-inside-async test, so it fails rather than hangs without the fix

* GROOVY-12715: list the async and await alternatives of castOperandExpression in the grammar doc

(cherry picked from commit cb6cd05)
@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.

3 participants