diff options
-rw-r--r-- | src/dotty/tools/dotc/core/SymDenotations.scala | 10 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/ExtensionMethods.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/MixinOps.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/transform/SymUtils.scala | 9 |
4 files changed, 18 insertions, 5 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala index f24c41ee2..9c6dde798 100644 --- a/src/dotty/tools/dotc/core/SymDenotations.scala +++ b/src/dotty/tools/dotc/core/SymDenotations.scala @@ -215,6 +215,10 @@ object SymDenotations { final def transformAnnotations(f: Annotation => Annotation)(implicit ctx: Context): Unit = annotations = annotations.mapConserve(f) + /** Keep only those annotations that satisfy `p` */ + final def filterAnnotations(p: Annotation => Boolean)(implicit ctx: Context): Unit = + annotations = annotations.filterConserve(p) + /** Optionally, the annotation matching the given class symbol */ final def getAnnotation(cls: Symbol)(implicit ctx: Context): Option[Annotation] = dropOtherAnnotations(annotations, cls) match { @@ -230,9 +234,9 @@ object SymDenotations { final def removeAnnotation(cls: Symbol)(implicit ctx: Context): Unit = annotations = myAnnotations.filterNot(_ matches cls) - /** Copy all annotations from given symbol by adding them to this symbol */ - final def addAnnotations(from: Symbol)(implicit ctx: Context): Unit = - from.annotations.foreach(addAnnotation) + /** Add all given annotations to this symbol */ + final def addAnnotations(annots: TraversableOnce[Annotation])(implicit ctx: Context): Unit = + annots.foreach(addAnnotation) @tailrec private def dropOtherAnnotations(anns: List[Annotation], cls: Symbol)(implicit ctx: Context): List[Annotation] = anns match { diff --git a/src/dotty/tools/dotc/transform/ExtensionMethods.scala b/src/dotty/tools/dotc/transform/ExtensionMethods.scala index ef0faae80..36a1b9b30 100644 --- a/src/dotty/tools/dotc/transform/ExtensionMethods.scala +++ b/src/dotty/tools/dotc/transform/ExtensionMethods.scala @@ -117,7 +117,7 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful imeth.flags | Final &~ (Override | Protected | AbsOverride), fullyParameterizedType(imeth.info, imeth.owner.asClass), privateWithin = imeth.privateWithin, coord = imeth.coord) - extensionMeth.addAnnotations(from = imeth)(ctx.withPhase(thisTransformer)) + extensionMeth.addAnnotations(imeth.annotations)(ctx.withPhase(thisTransformer)) // need to change phase to add tailrec annotation which gets removed from original method in the same phase. extensionMeth } diff --git a/src/dotty/tools/dotc/transform/MixinOps.scala b/src/dotty/tools/dotc/transform/MixinOps.scala index 48c6f9bea..3685a00fc 100644 --- a/src/dotty/tools/dotc/transform/MixinOps.scala +++ b/src/dotty/tools/dotc/transform/MixinOps.scala @@ -19,7 +19,7 @@ class MixinOps(cls: ClassSymbol, thisTransform: DenotTransformer)(implicit ctx: name = member.name.stripScala2LocalSuffix, flags = member.flags &~ Deferred, info = cls.thisType.memberInfo(member)).enteredAfter(thisTransform).asTerm - res.addAnnotations(member) + res.addAnnotations(member.annotations) res } diff --git a/src/dotty/tools/dotc/transform/SymUtils.scala b/src/dotty/tools/dotc/transform/SymUtils.scala index d3e029a74..14f6a2e22 100644 --- a/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/src/dotty/tools/dotc/transform/SymUtils.scala @@ -11,6 +11,7 @@ import Names._ import StdNames._ import NameOps._ import Flags._ +import Annotations._ import language.implicitConversions object SymUtils { @@ -90,4 +91,12 @@ class SymUtils(val self: Symbol) extends AnyVal { def implClass(implicit ctx: Context): Symbol = self.owner.info.decl(self.name.implClassName).symbol + + def annotationsCarrying(meta: ClassSymbol)(implicit ctx: Context): List[Annotation] = + self.annotations.filter(_.symbol.hasAnnotation(meta)) + + def withAnnotationsCarrying(from: Symbol, meta: ClassSymbol)(implicit ctx: Context): self.type = { + self.addAnnotations(from.annotationsCarrying(meta)) + self + } } |