@@ -16,9 +16,13 @@ import ast.tpd
16
16
/** This phase makes all erased term members of classes private so that they cannot
17
17
* conflict with non-erased members. This is needed so that subsequent phases like
18
18
* ResolveSuper that inspect class members work correctly.
19
- * The phase also replaces all expressions that appear in an erased context by
20
- * default values. This is necessary so that subsequent checking phases such
21
- * as IsInstanceOfChecker don't give false negatives.
19
+ * The phase also checks that `erased` definitions contain a call to `erasedValue`
20
+ * on their RHS. Then replaces all expressions that appear in an effectively
21
+ * erased context by default values. This is necessary so that subsequent checking
22
+ * phases such as IsInstanceOfChecker don't give false negatives.
23
+ *
24
+ * TODO: This does not belong in this phase as it has nothing to do with `erased`
25
+ * definitions. Move it out to keep logic clean.
22
26
* Finally, the phase replaces `compiletime.uninitialized` on the right hand side
23
27
* of a mutable field definition by `_`. This avoids a "is declared erased, but is
24
28
* in fact used" error in Erasure and communicates to Constructors that the
@@ -69,6 +73,12 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
69
73
else tree
70
74
71
75
private def trivialErasedTree (tree : Tree )(using Context ): Tree =
76
+ tree match
77
+ case tree : ValOrDefDef if ! tree.symbol.is(Inline ) && ! tree.symbol.is(Synthetic ) =>
78
+ if tree.rhs.symbol == defn.Predef_undefined then
79
+ report.warning(" Implementation of erased definition should be `erasedValue`. May require an import of `scala.comiletime.erasedValue`." , tree.rhs)
80
+ case _ =>
81
+
72
82
tree.tpe.widenTermRefExpr.dealias.normalized match
73
83
case ConstantType (c) => Literal (c)
74
84
case _ => ref(defn.Predef_undefined )
0 commit comments