[ 
https://issues.apache.org/jira/browse/GROOVY-12833?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18150642#comment-18150642
 ] 

ASF GitHub Bot commented on GROOVY-12833:
-----------------------------------------

codecov-commenter commented on PR #3360:
URL: https://github.com/apache/groovy/pull/3360#issuecomment-7154009827

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3360?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 Report
   :white_check_mark: All modified and coverable lines are covered by tests.
   :white_check_mark: Project coverage is 74.9541%. Comparing base 
([`5e36030`](https://app.codecov.io/gh/apache/groovy/commit/5e36030e384f5907ae31cfbb7e80a72378bc5261?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`5d0d76b`](https://app.codecov.io/gh/apache/groovy/commit/5d0d76b76f45fe1fb54d16259c7e13bd23f51047?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/3360/graphs/tree.svg?width=650&height=150&src=pr&token=1r45138NfQ&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)](https://app.codecov.io/gh/apache/groovy/pull/3360?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3360        +/-   ##
   ==================================================
   - Coverage     74.9577%   74.9541%   -0.0036%     
   + Complexity      48936      48931         -5     
   ==================================================
     Files            1768       1768                
     Lines          161255     161256         +1     
     Branches        31743      31743                
   ==================================================
   - Hits           120873     120868         -5     
   - Misses          28970      28974         +4     
   - Partials        11412      11414         +2     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3360?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[...oovy/ginq/provider/collection/GinqAstWalker.groovy](https://app.codecov.io/gh/apache/groovy/pull/3360?src=pr&el=tree&filepath=subprojects%2Fgroovy-ginq%2Fsrc%2Fmain%2Fgroovy%2Forg%2Fapache%2Fgroovy%2Fginq%2Fprovider%2Fcollection%2FGinqAstWalker.groovy&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VicHJvamVjdHMvZ3Jvb3Z5LWdpbnEvc3JjL21haW4vZ3Jvb3Z5L29yZy9hcGFjaGUvZ3Jvb3Z5L2dpbnEvcHJvdmlkZXIvY29sbGVjdGlvbi9HaW5xQXN0V2Fsa2VyLmdyb292eQ==)
 | `90.3776% <100.0000%> (+0.1337%)` | :arrow_up: |
   
   ... and [13 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3360/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   </details>
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test 
Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, 
report on failures, and find test suite problems.
   - :package: [JS Bundle 
Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save 
yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>




> GINQ: aliasing a method call on an aggregate in a groupby select fails with 
> "BUG! exception in phase 'conversion'"
> ------------------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12833
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12833
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Paul King
>            Priority: Major
>
> When a {{select}} clause following a {{groupby}} contains a method call 
> involving an aggregate function *and* that column is given an alias, 
> compilation fails with a {{BUG!}} exception instead of producing a result.
> {code:groovy}
> def nums = [1, 2, 3, 4]
> println GQ {
>     from n in nums
>     groupby n % 2 as parity
>     select parity, Math.round(avg(n)) as mean
> }
> {code}
> fails with:
> {noformat}
> BUG! exception in phase 'conversion' in source unit '...' Cannot cast object 
> 'org.codehaus.groovy.ast.expr.CastExpression@...[Math.round(this.avg(n)) as 
> mean]' with class 'org.codehaus.groovy.ast.expr.CastExpression' to class 
> 'org.codehaus.groovy.ast.expr.MethodCallExpression'
> Caused by: org.codehaus.groovy.runtime.typehandling.GroovyCastException: 
> Cannot cast object ...
> {noformat}
> The same happens for {{avg\(n).round() as mean}} and {{sum\(n).toString() as 
> total}}.
> Things that work:
> * without the alias: {{select parity, Math.round(avg\(n))}}
> * aggregate with alias: {{select parity, avg\(n) as mean}}
> * a cast instead of a method call: {{select parity, (avg\(n) as int) as mean}}
> The same crash also hides an intended syntax error. For a non-aggregate 
> method call with an alias:
> {code:groovy}
> def hello(x) { x }
> GQ { from n in [1, 2, 3] groupby n select n, hello(n) as h }.toList()
> {code}
> the expected error is "{{`this.hello\(n)` is not an aggregate function}}" (as 
> reported without the alias), but the same {{BUG!}} is thrown instead.
> *Cause:* in {{GinqAstWalker.validateGroupCols}}, {{isExpression(expr, 
> MethodCallExpression)}} unwraps the {{CastExpression}} that an alias creates, 
> but the following line casts the still-wrapped {{expr}} directly: 
> {{((MethodCallExpression) expr).implicitThis}}. The error message on the next 
> line already allows for a {{CastExpression}}, so only the unwrap is missing.
> Reproduced with 6.0.0 and 7.0.0-SNAPSHOT (master, 2026-11-24).
> The fix
> {code:groovy}
> def hello(x) { x }
> GQ { from n in [1, 2, 3] groupby n select n, hello(n) as h }.toList()
> {code}
> the expected error is "{{`this.hello\(n)` is not an aggregate function}}" (as 
> reported without the alias), but the same {{BUG!}} is thrown instead.
> *Cause:* in {{GinqAstWalker.validateGroupCols}}, {{isExpression(expr, 
> MethodCallExpression)}} unwraps the {{CastExpression}} that an alias creates, 
> but the following line casts the still-wrapped {{expr}} directly: 
> {{((MethodCallExpression) expr).implicitThis}}. The error message on the next 
> line already allows for a {{CastExpression}}, so only the unwrap is missing.
> Reproduced with 6.0.0 and 7.0.0-SNAPSHOT (master, 2026-11-24).



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to