Skip to content

Commit ceabdbd

Browse files
committed
Set field annotations immediately
1 parent f847ef6 commit ceabdbd

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

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

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,19 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase =>
108108
if (sym.isGetter) sym.info.resultType
109109
else /*sym.isSetter*/ sym.info.firstParamTypes.head
110110

111-
newSymbol(
111+
val fieldSym = newSymbol(
112112
owner = ctx.owner,
113113
name = sym.name.asTermName.fieldName,
114114
flags = Private | (if (sym.is(StableRealizable)) EmptyFlags else Mutable),
115115
info = fieldType,
116116
coord = tree.span
117-
).withAnnotationsCarrying(sym, defn.FieldMetaAnnot)
118-
.enteredAfter(thisPhase)
119-
}
120-
121-
def addAnnotations(denot: Denotation): Unit =
122-
denot match {
123-
case fieldDenot: SymDenotation if sym.annotations.nonEmpty =>
124-
val cpy = fieldDenot.copySymDenotation()
125-
cpy.annotations = atPhase(typerPhase)(sym.annotations.filterConserve { annot =>
126-
annot.hasOneOfMetaAnnotation(defn.FieldMetaAnnot)
127-
|| !annot.hasOneOfMetaAnnotation(defn.ExtFieldAccessorMetaAnnots.toList*)
128-
})
129-
cpy.installAfter(thisPhase)
130-
case _ => ()
117+
)
118+
fieldSym.annotations = sym.annotations.filterConserve { annot =>
119+
annot.hasOneOfMetaAnnotation(defn.FieldMetaAnnot)
120+
|| !annot.hasOneOfMetaAnnotation(defn.ExtFieldAccessorMetaAnnots.toList*)
131121
}
122+
fieldSym.enteredAfter(thisPhase)
123+
}
132124

133125
def removeUnwantedAnnotations(denot: SymDenotation, metaAnnotSym: ClassSymbol): Unit =
134126
if (sym.annotations.nonEmpty) {
@@ -186,7 +178,6 @@ class Memoize extends MiniPhase with IdentityDenotTransformer { thisPhase =>
186178
if isErasableBottomField(field, rhsClass) then erasedBottomTree(rhsClass)
187179
else transformFollowingDeep(ref(field))(using ctx.withOwner(sym))
188180
val getterDef = cpy.DefDef(tree)(rhs = getterRhs)
189-
addAnnotations(fieldDef.denot)
190181
removeUnwantedAnnotations(sym, defn.GetterMetaAnnot)
191182
Thicket(fieldDef, getterDef)
192183
else if sym.isSetter then

0 commit comments

Comments
 (0)