@@ -29,12 +29,12 @@ object ConstFold:
29
29
def Apply [T <: Apply ](tree : T )(using Context ): T =
30
30
tree.fun match
31
31
case Select (xt, op) if foldedBinops.contains(op) =>
32
- treeConstant(xt) match
33
- case Some (x) =>
32
+ xt match
33
+ case ConstantTree (x) =>
34
34
tree.args match
35
35
case yt :: Nil =>
36
- treeConstant(yt) match
37
- case Some (y) => tree.withFoldedType(foldBinop(op, x, y))
36
+ yt match
37
+ case ConstantTree (y) => tree.withFoldedType(foldBinop(op, x, y))
38
38
case _ => tree
39
39
case _ => tree
40
40
case _ => tree
@@ -46,8 +46,8 @@ object ConstFold:
46
46
47
47
def Select [T <: Select ](tree : T )(using Context ): T =
48
48
if foldedUnops.contains(tree.name) then
49
- treeConstant( tree.qualifier) match
50
- case Some (x) => tree.withFoldedType(foldUnop(tree.name, x))
49
+ tree.qualifier match
50
+ case ConstantTree (x) => tree.withFoldedType(foldUnop(tree.name, x))
51
51
case _ => tree
52
52
else tree
53
53
@@ -59,15 +59,16 @@ object ConstFold:
59
59
tree.withFoldedType(Constant (targ.tpe))
60
60
case _ => tree
61
61
62
- private def treeConstant (tree : Tree )(using Context ): Option [Constant ] =
63
- tree match
64
- case Inlined (_, Nil , expr) => treeConstant(expr)
65
- case Typed (expr, _) => treeConstant(expr)
66
- case Literal (c) if c.tag == Constants .NullTag => Some (c)
67
- case _ =>
68
- tree.tpe.widenTermRefExpr.normalized.simplified match
69
- case ConstantType (c) => Some (c)
70
- case _ => None
62
+ private object ConstantTree :
63
+ def unapply (tree : Tree )(using Context ): Option [Constant ] =
64
+ tree match
65
+ case Inlined (_, Nil , expr) => unapply(expr)
66
+ case Typed (expr, _) => unapply(expr)
67
+ case Literal (c) if c.tag == Constants .NullTag => Some (c)
68
+ case _ =>
69
+ tree.tpe.widenTermRefExpr.normalized.simplified match
70
+ case ConstantType (c) => Some (c)
71
+ case _ => None
71
72
72
73
extension [T <: Tree ](tree : T )(using Context )
73
74
private def withFoldedType (c : Constant | Null ): T =
0 commit comments