@@ -10,6 +10,7 @@ import Symbols._
1010import Types ._
1111import typer .RefChecks
1212import MegaPhase .MiniPhase
13+ import StdNames .nme
1314import ast .tpd
1415
1516/** This phase makes all erased term members of classes private so that they cannot
@@ -18,6 +19,10 @@ import ast.tpd
1819 * The phase also replaces all expressions that appear in an erased context by
1920 * default values. This is necessary so that subsequent checking phases such
2021 * as IsInstanceOfChecker don't give false negatives.
22+ * Finally, the phase replaces `compiletime.notInitialized` on the right hand side
23+ * of a mutable field definition by `_`. This avoids a "is declared erased, but is
24+ * in fact used" error in Erasure and communicates to Constructors that the
25+ * variable does not have an initializer.
2126 */
2227class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
2328 import tpd ._
@@ -39,9 +44,16 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
3944 else tree
4045
4146 override def transformValDef (tree : ValDef )(using Context ): Tree =
42- if (tree.symbol.isEffectivelyErased && ! tree.rhs.isEmpty)
47+ val sym = tree.symbol
48+ if sym.isEffectivelyErased && ! tree.rhs.isEmpty then
4349 cpy.ValDef (tree)(rhs = trivialErasedTree(tree))
44- else tree
50+ else tree.rhs match
51+ case rhs : TypeApply
52+ if rhs.symbol == defn.Compiletime_notInitialized
53+ && sym.is(Mutable ) && sym.owner.isClass =>
54+ cpy.ValDef (tree)(rhs = cpy.Ident (rhs)(nme.WILDCARD ))
55+ case _ =>
56+ tree
4557
4658 override def transformDefDef (tree : DefDef )(using Context ): Tree =
4759 if (tree.symbol.isEffectivelyErased && ! tree.rhs.isEmpty)
0 commit comments