@@ -19,10 +19,6 @@ import ast.tpd
19
19
* The phase also replaces all expressions that appear in an erased context by
20
20
* default values. This is necessary so that subsequent checking phases such
21
21
* as IsInstanceOfChecker don't give false negatives.
22
- * Finally, the phase replaces `compiletime.uninitialized` 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.
26
22
*/
27
23
class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
28
24
import tpd ._
@@ -34,39 +30,20 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
34
30
override def runsAfterGroupsOf : Set [String ] = Set (RefChecks .name, ExplicitOuter .name)
35
31
36
32
override def transformSym (sym : SymDenotation )(using Context ): SymDenotation =
37
- if (sym.isEffectivelyErased && sym.isTerm && ! sym.is(Private ) && sym.owner.isClass)
38
- sym.copySymDenotation(initFlags = sym.flags | Private )
39
- else sym
33
+ if ! sym.isEffectivelyErased || ! sym.isTerm || sym.is(Private ) || ! sym.owner.isClass then sym
34
+ else sym.copySymDenotation(initFlags = sym.flags | Private )
40
35
41
36
override def transformApply (tree : Apply )(using Context ): Tree =
42
- if (tree.fun.tpe.widen.isErasedMethod)
43
- cpy.Apply (tree)(tree.fun, tree.args.map(trivialErasedTree))
44
- else tree
45
-
46
- private def hasUninitializedRHS (tree : ValOrDefDef )(using Context ): Boolean =
47
- def recur (rhs : Tree ): Boolean = rhs match
48
- case rhs : RefTree =>
49
- rhs.symbol == defn.Compiletime_uninitialized
50
- && tree.symbol.is(Mutable ) && tree.symbol.owner.isClass
51
- case closureDef(ddef) if defn.isContextFunctionType(tree.tpt.tpe.dealias) =>
52
- recur(ddef.rhs)
53
- case _ =>
54
- false
55
- recur(tree.rhs)
37
+ if ! tree.fun.tpe.widen.isErasedMethod then tree
38
+ else cpy.Apply (tree)(tree.fun, tree.args.map(trivialErasedTree))
56
39
57
40
override def transformValDef (tree : ValDef )(using Context ): Tree =
58
- val sym = tree.symbol
59
- if tree.symbol.isEffectivelyErased && ! tree.rhs.isEmpty then
60
- cpy.ValDef (tree)(rhs = trivialErasedTree(tree))
61
- else if hasUninitializedRHS(tree) then
62
- cpy.ValDef (tree)(rhs = cpy.Ident (tree.rhs)(nme.WILDCARD ).withType(tree.tpt.tpe))
63
- else
64
- tree
41
+ if ! tree.symbol.isEffectivelyErased || tree.rhs.isEmpty then tree
42
+ else cpy.ValDef (tree)(rhs = trivialErasedTree(tree))
65
43
66
44
override def transformDefDef (tree : DefDef )(using Context ): Tree =
67
- if (tree.symbol.isEffectivelyErased && ! tree.rhs.isEmpty)
68
- cpy.DefDef (tree)(rhs = trivialErasedTree(tree))
69
- else tree
45
+ if ! tree.symbol.isEffectivelyErased || tree.rhs.isEmpty then tree
46
+ else cpy.DefDef (tree)(rhs = trivialErasedTree(tree))
70
47
71
48
private def trivialErasedTree (tree : Tree )(using Context ): Tree =
72
49
tree.tpe.widenTermRefExpr.dealias.normalized match
0 commit comments