[
https://issues.apache.org/jira/browse/GROOVY-8965?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17565424#comment-17565424
]
ASF GitHub Bot commented on GROOVY-8965:
----------------------------------------
blackdrag commented on PR #1742:
URL: https://github.com/apache/groovy/pull/1742#issuecomment-1181626022
> Another thing that surprised me is that LUB(Integer,Double) is Double, not
Number. I'm not sure why this is the case:
https://github.com/apache/groovy/blob/master/src/main/java/org/codehaus/groovy/ast/tools/WideningCategories.java#L349
WideningCategories was initially for assignment and in some cases compares.
Like: you can assign an Integer to a Double, but you cannot assign a Double to
an Integer. I highly doubt this will give you the right results for the
instanceof|| problem
> instanceof with || inserts wrong cast
> -------------------------------------
>
> Key: GROOVY-8965
> URL: https://issues.apache.org/jira/browse/GROOVY-8965
> Project: Groovy
> Issue Type: Bug
> Components: Static compilation
> Affects Versions: 2.5.5
> Reporter: Daniil Ovchinnikov
> Assignee: Eric Milles
> Priority: Major
>
> {code:java}
> @groovy.transform.CompileStatic
> def foo(a) {
> if (a instanceof Integer || a instanceof Double) {
> a.floatValue() // expected: cast to Number; actual: cast to Integer
> }
> }
> println foo(1d).class // CCE: java.lang.Double cannot be cast to
> java.lang.Integer
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)