Repository navigation
GROOVY-12715: let a cast apply to await and to an async closure - #3248
Conversation
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 Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ 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 🚀 New features to boost your workflow:
|
daniellansun
left a comment
There was a problem hiding this comment.
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.
…ils rather than hangs without the fix
…ression in the grammar doc
✅ All tests passed ✅🏷️ Commit: 85443e9 Learn more about TestLens at testlens.app/docs. |
* 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)
|
Merged. Thanks! |
awaitandasynchave their own alternatives in theexpressionrule (awaitExprAlt,asyncClosureExprAlt), but the operand of a cast is parsed bycastOperandExpression, which listed only another cast, apostfixExpressionand the unary operators. After a cast the two words therefore fell back to being identifiers:(BigDecimal) await(price)was a call to a method namedawaitwith one argument and(Awaitable<Integer>) async { 7 }a call to a method namedasyncwith a closure. At script level that is aMissingMethodException; 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).castOperandExpressiongains the two alternatives, with the same labels; the rule declaresbaseContext = expression, so they produce the same contexts andAstBuilder.visitAwaitExprAltandvisitAsyncClosureExprAltapply unchanged.Tests:
AsyncAwaitTestgains a cast applied toawaitwith one and with several arguments, the same inside an async task that binds aDataflowVariable(the shape that hung), and a cast applied to an async closure. On JDK 21AsyncAwaitTest(277 tests) andParserPositiveSyntaxTestpass;ParserNegativeSyntaxTestshows 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_Xas well.