jdaugherty opened a new pull request, #3087: URL: https://github.com/apache/groovy/pull/3087
Since GROOVY-10936 a ternary's type is the common supertype of its branches' types, but a class literal reported the class it names. A ternary choosing between two ternaries of class literals, such as `a ? b ? First : Second : c ? Third : Fourth`, was therefore typed as the classes' common supertype. Dynamic code compiled with indy then cast the chosen `Class` object to that type and failed with `ClassCastException: Cannot cast java.lang.Class to Marker`. `BinaryExpressionHelper.evaluateTernaryExpression()` types each branch with `StatementMetaTypeChooser.resolveType()`, which already answers `Class<T>` for a class expression, so a single-level ternary of class literals was fine; a ternary's own `getType()` is consulted when it is an operand of another ternary. `TernaryExpression.getType()` now gives a class literal operand the same `Class<T>` type. `groovy.operator.TernaryOperatorsTest.testNestedTernaryOfClassLiteralsIsJavaLangClass` returns and passes a nested ternary of class literals and checks the chosen class. It fails without the fix. - Jira: [GROOVY-12559](https://issues.apache.org/jira/browse/GROOVY-12559) - Reproducer: https://github.com/jdaugherty/groovy-ternary-class-literal-reproducer - Backport to `GROOVY_6_0_X`: https://github.com/jdaugherty/groovy/commit/937077ab9a59064254710c513e60b1fa64be391a, on the branch [`GROOVY-12559-6_0_X`](https://github.com/jdaugherty/groovy/tree/GROOVY-12559-6_0_X). - Backport to `GROOVY_5_1_X`: https://github.com/jdaugherty/groovy/commit/ad11e487df3bfb08b0ad5fe2cd6151c8067b043e, on the branch [`GROOVY-12559-5_1_X`](https://github.com/jdaugherty/groovy/tree/GROOVY-12559-5_1_X). It reproduces on 5.1.3, 6.0.0 and master with invokedynamic; 4.0.33, and classic call sites, are not affected. Could this be backported to 6.0.x and 5.x once it is merged? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
