eclipse-archived / ceylon

The Ceylon compiler, language module, and command line tools
http://ceylon-lang.org
Apache License 2.0
395 stars 62 forks source link

Can't Instantiate Array using Metamodel apply() method. #7390

Open Voiteh opened 5 years ago

Voiteh commented 5 years ago

It is not possible to instantiate Array<Integer>, by using 'Array<Integer>'.apply({1,2,3}). I made four unit test, which should in my opinion all pass but the last one fails, two are for ArrayList and two for Array to have proof I'm doing it right.

        shared test
    void shouldCreateArrayListByConstructor(){
        ArrayList<Integer>{
            elements = {1,2,3};
        };
    }

    shared test
    void shouldCreateArrayListUsingMetamodelApply(){
        `ArrayList<Integer>`.apply(0,1.5,{1,2,3});
    }
    shared test 
    void shouldCreateArrayByConstructor(){
        Array<Integer>({1,2,3});

    }
    shared test 
    void shouldCreateArrayUsingMetamodelApplyFAIL(){
        `Array<Integer>`.apply({1,2,3});
    }

It fails badly:

java.lang.ClassCastException: com.redhat.ceylon.compiler.java.language.ConstantIterable cannot be cast to [J
    at ceylon.language.Array.<init>(Array.java:614)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.ConstructorDispatch.$call$(ConstructorDispatch.java:610)
    at com.redhat.ceylon.compiler.java.Util.apply(Util.java:1634)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.apply(Metamodel.java:1891)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.ConstructorDispatch.apply(ConstructorDispatch.java:762)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.meta.ClassImpl.apply(ClassImpl.java:410)
    at ...

I think the same happens for other types like String, Float.