@@ -6,6 +6,7 @@ import DenotTransformers._
66import Phases .Phase
77import Contexts .Context
88import SymDenotations .SymDenotation
9+ import Denotations ._
910import Types ._
1011import Symbols ._
1112import SymUtils ._
@@ -50,7 +51,7 @@ import Decorators._
5051 if ! ddef.symbol.is(Deferred ) &&
5152 ! ddef.symbol.isConstructor && // constructors bodies are added later at phase Constructors
5253 ddef.rhs == EmptyTree =>
53- errorLackImplementation(ddef)
54+ errorLackImplementation(ddef)
5455 case tdef : TypeDef
5556 if tdef.symbol.isClass && ! tdef.symbol.is(Deferred ) && tdef.rhs == EmptyTree =>
5657 errorLackImplementation(tdef)
@@ -76,24 +77,33 @@ import Decorators._
7677
7778 ctx.newSymbol(
7879 owner = ctx.owner,
79- name = sym.name.asTermName.fieldName,
80+ name = sym.name.asTermName.fieldName,
8081 flags = Private | (if (sym is Stable ) EmptyFlags else Mutable ),
81- info = fieldType,
82- coord = tree.pos)
83- .withAnnotationsCarrying(sym, defn.FieldMetaAnnot )
84- .enteredAfter(thisTransform)
82+ info = fieldType,
83+ coord = tree.pos
84+ ) .withAnnotationsCarrying(sym, defn.FieldMetaAnnot )
85+ .enteredAfter(thisTransform)
8586 }
8687
87- /** Can be used to filter annotations on getters and setters; not used yet */
88- def keepAnnotations (denot : SymDenotation , meta : ClassSymbol ) = {
89- val cpy = sym.copySymDenotation()
90- cpy.filterAnnotations(_.symbol.derivesFrom(meta))
91- if (cpy.annotations ne denot.annotations) cpy.installAfter(thisTransform)
92- }
88+ def addAnnotations (denot : Denotation ): Unit =
89+ denot match {
90+ case fieldDenot : SymDenotation if sym.annotations.nonEmpty =>
91+ val cpy = fieldDenot.copySymDenotation()
92+ cpy.annotations = sym.annotations
93+ cpy.installAfter(thisTransform)
94+ case _ => ()
95+ }
96+
97+ def removeAnnotations (denot : SymDenotation ): Unit =
98+ if (sym.annotations.nonEmpty) {
99+ val cpy = sym.copySymDenotation()
100+ cpy.annotations = Nil
101+ cpy.installAfter(thisTransform)
102+ }
93103
94104 lazy val field = sym.field.orElse(newField).asTerm
95105
96- def adaptToField (tree : Tree ) =
106+ def adaptToField (tree : Tree ): Tree =
97107 if (tree.isEmpty) tree else tree.ensureConforms(field.info.widen)
98108
99109 val NoFieldNeeded = Lazy | Deferred | JavaDefined | (if (ctx.settings.YnoInline .value) EmptyFlags else Inline )
@@ -125,14 +135,18 @@ import Decorators._
125135 if (isErasableBottomField(rhsClass)) erasedBottomTree(rhsClass)
126136 else transformFollowingDeep(ref(field))(ctx.withOwner(sym), info)
127137 val getterDef = cpy.DefDef (tree)(rhs = getterRhs)
138+ addAnnotations(fieldDef.denot)
139+ removeAnnotations(sym)
128140 Thicket (fieldDef, getterDef)
129141 } else if (sym.isSetter) {
130- if (! sym.is(ParamAccessor )) { val Literal (Constant (())) = tree.rhs } // this is intended as an assertion
131- field.setFlag(Mutable ) // necessary for vals mixed in from Scala2 traits
142+ if (! sym.is(ParamAccessor )) { val Literal (Constant (())) = tree.rhs } // This is intended as an assertion
143+ field.setFlag(Mutable ) // Necessary for vals mixed in from Scala2 traits
132144 if (isErasableBottomField(tree.vparamss.head.head.tpt.tpe.classSymbol)) tree
133145 else {
134146 val initializer = Assign (ref(field), adaptToField(ref(tree.vparamss.head.head.symbol)))
135- cpy.DefDef (tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym), info))
147+ val setterDef = cpy.DefDef (tree)(rhs = transformFollowingDeep(initializer)(ctx.withOwner(sym), info))
148+ removeAnnotations(sym)
149+ setterDef
136150 }
137151 }
138152 else tree // curiously, some accessors from Scala2 have ' ' suffixes. They count as
0 commit comments