@@ -4,6 +4,7 @@ import org.junit.runner.RunWith
44import org .junit .runners .JUnit4
55import org .junit .Test
66import scala .tools .asm .Opcodes
7+ import scala .tools .nsc .backend .jvm .AsmUtils
78import scala .tools .nsc .backend .jvm .CodeGenTools ._
89import org .junit .Assert ._
910import scala .collection .JavaConverters ._
@@ -36,4 +37,44 @@ class BytecodeTests {
3637 assertTrue(getSingleMethod(c, " f" ).instructions.count(_.isInstanceOf [TableSwitch ]) == 1 )
3738 assertTrue(getSingleMethod(c, " g" ).instructions.count(_.isInstanceOf [LookupSwitch ]) == 1 )
3839 }
40+
41+ @ Test
42+ def t8926 (): Unit = {
43+ import scala .reflect .internal .util .BatchSourceFile
44+
45+ // this test cannot be implemented using partest because of its mixed-mode compilation strategy:
46+ // partest first compiles all files with scalac, then the java files, and then again the scala
47+ // using the output classpath. this shadows the bug SI-8926.
48+
49+ val annotA =
50+ """ import java.lang.annotation.Retention;
51+ |import java.lang.annotation.RetentionPolicy;
52+ |@Retention(RetentionPolicy.RUNTIME)
53+ |public @interface AnnotA { }
54+ """ .stripMargin
55+ val annotB = " public @interface AnnotB { }"
56+
57+ val scalaSrc =
58+ """ @AnnotA class A
59+ |@AnnotB class B
60+ """ .stripMargin
61+
62+ val compiler = newCompiler()
63+ val run = new compiler.Run ()
64+ run.compileSources(List (new BatchSourceFile (" AnnotA.java" , annotA), new BatchSourceFile (" AnnotB.java" , annotB), new BatchSourceFile (" Test.scala" , scalaSrc)))
65+ val outDir = compiler.settings.outputDirs.getSingleOutput.get
66+ val outfiles = (for (f <- outDir.iterator if ! f.isDirectory) yield (f.name, f.toByteArray)).toList
67+
68+ def check (classfile : String , annotName : String ) = {
69+ val f = (outfiles collect { case (`classfile`, bytes) => AsmUtils .readClass(bytes) }).head
70+ val descs = f.visibleAnnotations.asScala.map(_.desc).toList
71+ assertTrue(descs.toString, descs exists (_ contains annotName))
72+ }
73+
74+ check(" A.class" , " AnnotA" )
75+
76+ // known issue SI-8928: the visibility of AnnotB should be CLASS, but annotation classes without
77+ // a @Retention annotation are currently emitted as RUNTIME.
78+ check(" B.class" , " AnnotB" )
79+ }
3980}
0 commit comments