Thodoris Sotiropoulos created GROOVY-11476:
----------------------------------------------

             Summary: 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


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
(v8.20.10#820010)

Reply via email to