@@ -4,6 +4,7 @@ import org.junit.runner.RunWith
4
4
import org .junit .runners .JUnit4
5
5
import org .junit .Test
6
6
import scala .tools .asm .Opcodes
7
+ import scala .tools .nsc .backend .jvm .AsmUtils
7
8
import scala .tools .nsc .backend .jvm .CodeGenTools ._
8
9
import org .junit .Assert ._
9
10
import scala .collection .JavaConverters ._
@@ -36,4 +37,44 @@ class BytecodeTests {
36
37
assertTrue(getSingleMethod(c, " f" ).instructions.count(_.isInstanceOf [TableSwitch ]) == 1 )
37
38
assertTrue(getSingleMethod(c, " g" ).instructions.count(_.isInstanceOf [LookupSwitch ]) == 1 )
38
39
}
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
+ }
39
80
}
0 commit comments