Skip to content

Commit 2ce940a

Browse files
committed
Copy @field annotations from getters to fields.
For the moment, we keep all annotations on getters and setters, but this could be changed.
1 parent 291aeca commit 2ce940a

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ class Definitions {
346346
lazy val UncheckedStableAnnot = ctx.requiredClass("scala.annotation.unchecked.uncheckedStable")
347347
lazy val UncheckedVarianceAnnot = ctx.requiredClass("scala.annotation.unchecked.uncheckedVariance")
348348
lazy val VolatileAnnot = ctx.requiredClass("scala.volatile")
349+
lazy val FieldMetaAnnot = ctx.requiredClass("scala.annotation.meta.field")
350+
lazy val GetterMetaAnnot = ctx.requiredClass("scala.annotation.meta.getter")
351+
lazy val SetterMetaAnnot = ctx.requiredClass("scala.annotation.meta.setter")
349352

350353
// convenient one-parameter method types
351354
def methOfAny(tp: Type) = MethodType(List(AnyType), tp)

src/dotty/tools/dotc/transform/Memoize.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ import Decorators._
5050
name = sym.name.asTermName.fieldName,
5151
flags = Private | (if (sym is Stable) EmptyFlags else Mutable),
5252
info = sym.info.resultType,
53-
coord = tree.pos).enteredAfter(thisTransform)
53+
coord = tree.pos)
54+
.withAnnotationsCarrying(sym, defn.FieldMetaAnnot)
55+
.enteredAfter(thisTransform)
56+
57+
/** Can be used to filter annotations on getters and setters; not used yet */
58+
def keepAnnotations(denot: SymDenotation, meta: ClassSymbol) = {
59+
val cpy = sym.copySymDenotation()
60+
cpy.filterAnnotations(_.symbol.derivesFrom(meta))
61+
if (cpy.annotations ne denot.annotations) cpy.installAfter(thisTransform)
62+
}
5463

5564
lazy val field = sym.field.orElse(newField).asTerm
5665
if (sym.is(Accessor, butNot = NoFieldNeeded))

0 commit comments

Comments
 (0)