Skip to content

Commit 5af4a13

Browse files
committed
Fix visibility of annotations
`isRuntimeVisible` and `retentionPolicyOf` had two different ways to get the retention policy of an annotation and they were both wrong. Fix retentionPolicyOf` and use it in `isRuntimeVisible`
1 parent d7b54ea commit 5af4a13

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,15 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
206206
implicit val ConstantClassTag: ClassTag[Constant] = ClassTag[Constant](classOf[Constant])
207207
implicit val ClosureTag: ClassTag[Closure] = ClassTag[Closure](classOf[Closure])
208208

209-
def isRuntimeVisible(annot: Annotation): Boolean = {
210-
annot.atp.typeSymbol.getAnnotation(AnnotationRetentionAttr) match {
211-
case Some(retentionAnnot) =>
212-
retentionAnnot.tree.find(_.symbol == AnnotationRetentionRuntimeAttr).isDefined
213-
case _ =>
214-
// SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the
215-
// annotation is emitted with visibility `RUNTIME`
216-
// dotty bug: #389
217-
true
209+
def isRuntimeVisible(annot: Annotation): Boolean =
210+
if (toDenot(annot.atp.typeSymbol).hasAnnotation(AnnotationRetentionAttr))
211+
retentionPolicyOf(annot) == AnnotationRetentionRuntimeAttr
212+
else {
213+
// SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the
214+
// annotation is emitted with visibility `RUNTIME`
215+
// dotty bug: #389
216+
true
218217
}
219-
}
220218

221219
def shouldEmitAnnotation(annot: Annotation): Boolean = {
222220
annot.symbol.isJavaDefined &&
@@ -226,7 +224,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
226224

227225
private def retentionPolicyOf(annot: Annotation): Symbol =
228226
annot.atp.typeSymbol.getAnnotation(AnnotationRetentionAttr).
229-
flatMap(_.argument(0).map(_.symbol)).getOrElse(AnnotationRetentionClassAttr)
227+
flatMap(_.argumentConstant(0).map(_.symbolValue)).getOrElse(AnnotationRetentionClassAttr)
230228

231229
private def emitArgument(av: AnnotationVisitor,
232230
name: String,

0 commit comments

Comments
 (0)