ArraySequence may not have zero elements for `Declaration` in annotations #378

Closed
loicrouchon opened this Issue Dec 28, 2013 · 1 comment

Comments

Projects
None yet
1 participant
Member

loicrouchon commented Dec 28, 2013

Following code is failing at runtime

import ceylon.language.meta.declaration { FunctionDeclaration, Declaration }

shared final annotation class MyAnnotation(shared [Declaration*] args)
        satisfies OptionalAnnotation<MyAnnotation, FunctionDeclaration> {
}

shared annotation MyAnnotation myAnnotation([Declaration*] args = [])
        => MyAnnotation(args);

myAnnotation shared void foo() {}

shared void run() {
    value packages = `module bug.metamodel.sequence.declaration`.members;
    for (pkg in packages) {
        value members = pkg.annotatedMembers<FunctionDeclaration, MyAnnotation>();
        print(members);
    }
}

With exception:

ceylon run: While reflectively instantiating class bug.metamodel.sequence.
declaration.MyAnnotation
java.lang.RuntimeException: While reflectively instantiating class bug.metamodel.sequence.declaration.MyAnnotation
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.addAnnotation(Metamodel.java:582)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.annotations(Metamodel.java:624)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.annotations(Metamodel.java:611)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Predicates$AnnotatedWith.accept(Predicates.java:328)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Predicates$AnnotatedWith.accept(Predicates.java:312)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Predicates$And.accept(Predicates.java:115)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.FreePackage.filteredMembers(FreePackage.java:151)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.FreePackage.annotatedMembers(FreePackage.java:138)
    at bug.metamodel.sequence.declaration.run_.run(run.ceylon:16)
    at bug.metamodel.sequence.declaration.run_.main(run.ceylon)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at ceylon.modules.api.runtime.SecurityActions.invokeRunInternal(SecurityActions.java:58)
    at ceylon.modules.api.runtime.SecurityActions.invokeRun(SecurityActions.java:48)
    at ceylon.modules.api.runtime.AbstractRuntime.invokeRun(AbstractRuntime.java:85)
    at ceylon.modules.api.runtime.AbstractRuntime.execute(AbstractRuntime.java:145)
    at ceylon.modules.api.runtime.AbstractRuntime.execute(AbstractRuntime.java:129)
    at ceylon.modules.Main.execute(Main.java:69)
    at ceylon.modules.Main.main(Main.java:42)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at org.jboss.modules.Module.run(Module.java:270)
    at org.jboss.modules.Main.main(Main.java:294)
    at ceylon.modules.bootstrap.CeylonRunTool.run(CeylonRunTool.java:208)
    at com.redhat.ceylon.common.tools.CeylonTool.run(CeylonTool.java:343)
    at com.redhat.ceylon.common.tools.CeylonTool.execute(CeylonTool.java:283)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:606)
    at com.redhat.ceylon.launcher.Launcher.run(Launcher.java:89)
    at com.redhat.ceylon.launcher.Launcher.main(Launcher.java:21)
Caused by: java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:526)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.addAnnotation(Metamodel.java:577)
    ... 35 more
Caused by: ceylon.language.AssertionException "ArraySequence may not have zero elements"
    at ceylon.language.ArraySequence.<init>(ArraySequence.java:139)
    at ceylon.language.ArraySequence.instance(ArraySequence.java:119)
    at com.redhat.ceylon.compiler.java.runtime.metamodel.Metamodel.parseMetamodelReferences(Metamodel.java:779)
    at bug.metamodel.sequence.declaration.MyAnnotation.<init>(run.ceylon:4)
    ... 40 more

If you use String instead of Declaration then it will not fail.

I test with some subclasses of Declaration like FunctionDeclaration and there is the same issue.

@loicrouchon loicrouchon added a commit to ceylon/ceylon.build that referenced this issue Dec 30, 2013

@loicrouchon loicrouchon #32 Add internal and dependencies attributes to goal annotation
Note that dependencies are treated as String because of
ceylon/ceylon.language#378
When it will be fixed, dependencies will have [FunctionDeclaration*] type
380d8df

loicrouchon referenced this issue in ceylon/ceylon.build Dec 30, 2013

Closed

Allow declarating definition of goals #32

@tombentley tombentley added a commit that referenced this issue Mar 18, 2014

@tombentley tombentley Issue #378: Add a test b3ebd50
Member

loicrouchon commented Mar 22, 2014

It's now working fine.

Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment