[
https://issues.apache.org/jira/browse/GROOVY-8965?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17564276#comment-17564276
]
Paul King commented on GROOVY-8965:
-----------------------------------
I think the general idea for the "full" solution was that even when we fully
supported Union/Intersection types, that if the LUB was available, we could
happily use that as an efficiency shortcut. However, if there was no LUB or the
LUB was inaccessible, e.g. the LUB for StringBuilder || StringBuffer is package
private, then we'd retain that knowledge and use Union/Intersection types. You
are right - that needs handling further down the line. If your solution to
handle the simple case, leaves open the extension to handle the more complex
case later, then it seems reasonable to at least move ourselves forward on that
part.
> 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)