From a4fea264bd7348f930b47a9f3b08e94693e73564 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Wed, 30 Nov 2016 21:11:34 +0100 Subject: 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` --- .../tools/backend/jvm/DottyBackendInterface.scala | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) (limited to 'compiler/src/dotty/tools/backend') diff --git a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala index 8a29cd5e2..6a4046dda 100644 --- a/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala +++ b/compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala @@ -206,17 +206,15 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma implicit val ConstantClassTag: ClassTag[Constant] = ClassTag[Constant](classOf[Constant]) implicit val ClosureTag: ClassTag[Closure] = ClassTag[Closure](classOf[Closure]) - def isRuntimeVisible(annot: Annotation): Boolean = { - annot.atp.typeSymbol.getAnnotation(AnnotationRetentionAttr) match { - case Some(retentionAnnot) => - retentionAnnot.tree.find(_.symbol == AnnotationRetentionRuntimeAttr).isDefined - case _ => - // SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the - // annotation is emitted with visibility `RUNTIME` - // dotty bug: #389 - true + def isRuntimeVisible(annot: Annotation): Boolean = + if (toDenot(annot.atp.typeSymbol).hasAnnotation(AnnotationRetentionAttr)) + retentionPolicyOf(annot) == AnnotationRetentionRuntimeAttr + else { + // SI-8926: if the annotation class symbol doesn't have a @RetentionPolicy annotation, the + // annotation is emitted with visibility `RUNTIME` + // dotty bug: #389 + true } - } def shouldEmitAnnotation(annot: Annotation): Boolean = { annot.symbol.isJavaDefined && @@ -226,7 +224,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma private def retentionPolicyOf(annot: Annotation): Symbol = annot.atp.typeSymbol.getAnnotation(AnnotationRetentionAttr). - flatMap(_.argument(0).map(_.symbol)).getOrElse(AnnotationRetentionClassAttr) + flatMap(_.argumentConstant(0).map(_.symbolValue)).getOrElse(AnnotationRetentionClassAttr) private def emitArgument(av: AnnotationVisitor, name: String, -- cgit v1.2.3