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

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

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

   ## 
[Codecov](https://app.codecov.io/gh/apache/groovy/pull/3087?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 73.6782%. Comparing base 
([`0c7c1c1`](https://app.codecov.io/gh/apache/groovy/commit/0c7c1c1733871035166f5dd731903d2113876002?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache))
 to head 
([`daa51d8`](https://app.codecov.io/gh/apache/groovy/commit/daa51d82b7d8713793fae8632f3ea40ddbb45bd8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 3 commits behind head on master.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   [![Impacted file tree 
graph](https://app.codecov.io/gh/apache/groovy/pull/3087/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/3087?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   ```diff
   @@                Coverage Diff                 @@
   ##               master      #3087        +/-   ##
   ==================================================
   + Coverage     73.6739%   73.6782%   +0.0043%     
   - Complexity      42586      42591         +5     
   ==================================================
     Files            1678       1678                
     Lines          146911     146916         +5     
     Branches        27791      27791                
   ==================================================
   + Hits           108235     108245        +10     
   + Misses          28525      28522         -3     
   + Partials        10151      10149         -2     
   ```
   
   | [Files with missing 
lines](https://app.codecov.io/gh/apache/groovy/pull/3087?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
 | Coverage Δ | |
   |---|---|---|
   | 
[...rg/codehaus/groovy/ast/expr/TernaryExpression.java](https://app.codecov.io/gh/apache/groovy/pull/3087?src=pr&el=tree&filepath=src%2Fmain%2Fjava%2Forg%2Fcodehaus%2Fgroovy%2Fast%2Fexpr%2FTernaryExpression.java&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3JjL21haW4vamF2YS9vcmcvY29kZWhhdXMvZ3Jvb3Z5L2FzdC9leHByL1Rlcm5hcnlFeHByZXNzaW9uLmphdmE=)
 | `96.0000% <100.0000%> (+1.0000%)` | :arrow_up: |
   
   ... and [13 files with indirect coverage 
changes](https://app.codecov.io/gh/apache/groovy/pull/3087/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>




> Ternary of two ternaries of class literals is cast to the classes' common 
> supertype under invokedynamic
> -------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-12559
>                 URL: https://issues.apache.org/jira/browse/GROOVY-12559
>             Project: Groovy
>          Issue Type: Bug
>          Components: Compiler
>    Affects Versions: 5.1.3, 6.0.0
>            Reporter: James Daugherty
>            Priority: Major
>
> Since 5.0.0-alpha-4 (GROOVY-10936) the type of a ternary expression is the 
> common supertype of its branches' types. A class literal's type is the class 
> it names, not {{java.lang.Class}}, so a ternary that chooses between two 
> ternaries of class literals
> {code:groovy}
> interface Marker {}
> class First implements Marker {}
> class Second implements Marker {}
> class Third implements Marker {}
> class Fourth implements Marker {}
> class Chooser {
>     Class<?> choose(boolean a, boolean b, boolean c) {
>         a ? (b ? First : Second) : (c ? Third : Fourth)
>     }
> }
> assert new Chooser().choose(false, true, true) == Third
> {code}
> is typed as the classes' common supertype, {{Marker}}. The chosen {{Class}} 
> object is then converted _from_ {{Marker}} wherever it is used: returned, 
> passed as an argument, or assigned to a typed variable. With invokedynamic 
> that conversion is a {{cast}} call site declared as {{(Marker)Class}}, and 
> linking it casts the {{Class}} object to {{Marker}}:
> {noformat}
> java.lang.ClassCastException: Cannot cast java.lang.Class to Marker
> {noformat}
> Groovy 4, and Groovy 5 and 6 with classic call sites, return the chosen 
> class. A single-level ternary of class literals, {{a ? First : Second}}, is 
> unaffected, because the bytecode writer resolves a class literal operand to 
> {{Class<First>}} itself; a ternary's own type is consulted only when it is an 
> operand of another ternary. A Grails application moving from classic call 
> sites to invokedynamic (the Grails 9 default) meets this in code that picks a 
> class by conditions.
> *Reproducer:* 
> https://github.com/jdaugherty/groovy-ternary-class-literal-reproducer 
> ({{./run.sh 4.0.33 5.1.3 6.0.0}}): returning the chosen class and passing it 
> as an argument both fail on 5.1.3 and 6.0.0 with indy, and pass on 4.0.33 and 
> with classic call sites.
> *Cause:* {{TernaryExpression.getType()}} returns 
> {{WideningCategories.lowestUpperBound()}} of its branches' {{getType()}}, and 
> {{ClassExpression.getType()}} is the class the literal names. 
> {{BinaryExpressionHelper.evaluateTernaryExpression()}} types each branch with 
> {{StatementMetaTypeChooser.resolveType()}}, which answers {{Class<T>}} for a 
> class expression but {{getType()}} for a nested ternary. So the inner 
> ternaries are typed {{Marker}}, the outer ternary's common type is 
> {{Marker}}, and the operand stack carries {{Marker}} for a value that is a 
> {{Class}}. The conversion to {{Class}} is then written as {{invokedynamic 
> cast:(LMarker;)Ljava/lang/Class;}}, whose method type makes the JVM cast the 
> argument to {{Marker}} before the call site sees it. Classic call sites 
> convert the value to {{Class}} directly and accept it.
> *Proposed fix:* in {{TernaryExpression.getType()}}, give a class literal 
> operand the type {{Class<T>}}, as {{StatementMetaTypeChooser.resolveType()}} 
> does, so a ternary of class literals is typed {{Class}} wherever it appears. 
> A patch with a test follows as a pull request against master, with backports 
> for the 6.0.x and 5.1.x lines.



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

Reply via email to