@@ -16,9 +16,13 @@ import ast.tpd
1616/** This phase makes all erased term members of classes private so that they cannot
1717 * conflict with non-erased members. This is needed so that subsequent phases like
1818 * 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.
2226 * Finally, the phase replaces `compiletime.uninitialized` on the right hand side
2327 * of a mutable field definition by `_`. This avoids a "is declared erased, but is
2428 * in fact used" error in Erasure and communicates to Constructors that the
@@ -69,6 +73,12 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
6973 else tree
7074
7175 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+
7282 tree.tpe.widenTermRefExpr.dealias.normalized match
7383 case ConstantType (c) => Literal (c)
7484 case _ => ref(defn.Predef_undefined )
0 commit comments