[
https://issues.apache.org/jira/browse/GROOVY-11476?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18149219#comment-18149219
]
Daniel Sun commented on GROOVY-11476:
-------------------------------------
Fixed on master; added a regression test in
763480ea70fbffdacd23e0633a8cca12317bcd77
(https://github.com/apache/groovy/commit/763480ea70fbffdacd23e0633a8cca12317bcd77).
> inferring numeric values can lead to CCE
> ----------------------------------------
>
> Key: GROOVY-11476
> URL: https://issues.apache.org/jira/browse/GROOVY-11476
> Project: Groovy
> Issue Type: Bug
> Components: Static Type Checker
> Reporter: Thodoris Sotiropoulos
> Assignee: Daniel Sun
> Priority: Minor
> Fix For: 7.0.0-alpha-1
>
>
> Maybe related to GROOVY-11470.
> I have the following program
> {code:java}
> class Test {
> public static void main(String[] args) {
> m((Double) 2.0, (Integer) 1).compareTo(new Object());
> }
> public static <T> T m(T x, T y) { return x; }
> } {code}
> h3. Actual behavior
> The code compiles, but I get CCE at runtime.
> {code:java}
> Exception in thread "main" java.lang.ClassCastException: class
> java.lang.Object cannot be cast to class java.lang.Double (java.lang.Object
> and java.lang.Double are in module java.base of loader 'bootstrap')
> at java.base/java.lang.Double.compareTo(Double.java:49)
> at Test.main(test.groovy:3) {code}
> h3. Expected behavior
> The code should have been rejected.
> h3. Notes
> I think the problem is because the inferred return type of method "m()" is
> Number & Comparable.
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)