@@ -6,6 +6,7 @@ import DenotTransformers._
6
6
import Phases .Phase
7
7
import Contexts .Context
8
8
import SymDenotations .SymDenotation
9
+ import Denotations ._
9
10
import Types ._
10
11
import Symbols ._
11
12
import SymUtils ._
@@ -50,7 +51,7 @@ import Decorators._
50
51
if ! ddef.symbol.is(Deferred ) &&
51
52
! ddef.symbol.isConstructor && // constructors bodies are added later at phase Constructors
52
53
ddef.rhs == EmptyTree =>
53
- errorLackImplementation(ddef)
54
+ errorLackImplementation(ddef)
54
55
case tdef : TypeDef
55
56
if tdef.symbol.isClass && ! tdef.symbol.is(Deferred ) && tdef.rhs == EmptyTree =>
56
57
errorLackImplementation(tdef)
@@ -76,24 +77,33 @@ import Decorators._
76
77
77
78
ctx.newSymbol(
78
79
owner = ctx.owner,
79
- name = sym.name.asTermName.fieldName,
80
+ name = sym.name.asTermName.fieldName,
80
81
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)
85
86
}
86
87
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
+ }
93
103
94
104
lazy val field = sym.field.orElse(newField).asTerm
95
105
96
- def adaptToField (tree : Tree ) =
106
+ def adaptToField (tree : Tree ): Tree =
97
107
if (tree.isEmpty) tree else tree.ensureConforms(field.info.widen)
98
108
99
109
val NoFieldNeeded = Lazy | Deferred | JavaDefined | (if (ctx.settings.YnoInline .value) EmptyFlags else Inline )
@@ -125,14 +135,18 @@ import Decorators._
125
135
if (isErasableBottomField(rhsClass)) erasedBottomTree(rhsClass)
126
136
else transformFollowingDeep(ref(field))(ctx.withOwner(sym), info)
127
137
val getterDef = cpy.DefDef (tree)(rhs = getterRhs)
138
+ addAnnotations(fieldDef.denot)
139
+ removeAnnotations(sym)
128
140
Thicket (fieldDef, getterDef)
129
141
} 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
132
144
if (isErasableBottomField(tree.vparamss.head.head.tpt.tpe.classSymbol)) tree
133
145
else {
134
146
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
136
150
}
137
151
}
138
152
else tree // curiously, some accessors from Scala2 have ' ' suffixes. They count as
0 commit comments