Open
Description
Compiler version
3.4.0-RC4
Minimized code
// MyAnnot.java
package lib;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.TYPE, ElementType.METHOD, ElementType.CONSTRUCTOR, ElementType.ANNOTATION_TYPE,
ElementType.PACKAGE, ElementType.FIELD, ElementType.LOCAL_VARIABLE })
public @interface MyAnnot {
Class<?> reify() default Object.class;
Class<?>[] args() default {};
}
// MyAnnotated.java
package lib;
public class MyAnnotated {
@MyAnnot(reify = String.class)
public static int method1() { return 23; }
@MyAnnot(reify = int.class)
public static int method2() { return 23; }
@MyAnnot(reify = long.class)
public static int method3() { return 23; }
@MyAnnot(args = {String.class})
public static int method4() { return 23; }
@MyAnnot(args = {int.class})
public static int method5() { return 23; }
@MyAnnot(args = {long.class})
public static int method6() { return 23; }
}
Output
when I use -Xprint:parser
we get this result for MyAnnotated.java
package lib {
object MyAnnotated() {
@MyAnnot(reify = _root_.scala.Predef.classOf[String]) <static> def method1()
: scala.Int = _root_.scala.Predef.???
<static> def method2(): scala.Int = _root_.scala.Predef.???
<static> def method3(): scala.Int = _root_.scala.Predef.???
@MyAnnot(args = _root_.scala.Array(_root_.scala.Predef.classOf[String]))
<static> def method4(): scala.Int = _root_.scala.Predef.???
<static> def method5(): scala.Int = _root_.scala.Predef.???
<static> def method6(): scala.Int = _root_.scala.Predef.???
}
class MyAnnotated private[this](x$1: scala.Unit) extends Object {
def <init>() = _root_.scala.Predef.???
}
}
so as you can see when there is a primitive class argument to the annotation (either a direct parameter, or an array argument) then the entire annotation is dropped silently, but if it is a reference class then its ok?
Expectation
firstly - all methods should have an annotation (as accepted by javac), second it's strange that it is silently ignored (is anything else silently dropped?). Note that Scala 2.13 parser also has the exact same behavior - so I put this as low priority