Thodoris Sotiropoulos created GROOVY-11440:
----------------------------------------------

             Summary: invalid reference to an array constructor leads to type 
unsafe results
                 Key: GROOVY-11440
                 URL: https://issues.apache.org/jira/browse/GROOVY-11440
             Project: Groovy
          Issue Type: Bug
          Components: Static Type Checker
            Reporter: Thodoris Sotiropoulos


I have the following program
{code:java}
import java.util.function.*;

class A{
}
class Test {
  public static void main(String[] args) {
    Function<Object, A[]> x = A[]::new;
    A[] y = x.apply(new Object());
  }
} {code}
h3. Actual behavior

The code compiles, and I get a ClassCastException:
{code:java}
Exception in thread "main" 
org.codehaus.groovy.runtime.typehandling.GroovyCastException: Cannot cast 
object 'java.lang.Object@63d4e2ba' with class 'java.lang.Object' to class 'int'
    at 
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.castToNumber(DefaultTypeTransformation.java:177)
    at 
org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation.intUnbox(DefaultTypeTransformation.java:85)
    at Test.ctorRef$main$0(test.groovy)
    at Test.main(test.groovy:13) {code}
h3. Actual behavior

The code should have been rejected.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to