Skip to content

Commit 77bba39

Browse files
author
gan74
committed
Fix ConstantFold folding constant funcs without calling them
1 parent dea8fb2 commit 77bba39

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/ConstantFold.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,16 +139,16 @@ import Simplify.desugarIdent
139139
// Block(List(lhs),
140140
// ref(defn.throwMethod).appliedTo(New(defn.ArithmeticExceptionClass.typeRef, defn.ArithmeticExceptionClass_stringConstructor, Literal(Constant("/ by zero")) :: Nil)))
141141

142-
case _ =>
143-
val lhType = lhs.tpe.widenTermRefExpr
144-
val rhType = rhs.tpe.widenTermRefExpr
145-
(lhType, rhType) match {
142+
case (l: Literal, r: Literal) =>
143+
(l.tpe.widenTermRefExpr, r.tpe.widenTermRefExpr) match {
146144
case (ConstantType(_), ConstantType(_)) =>
147145
val s = ConstFold.apply(t)
148146
if ((s ne null) && s.tpe.isInstanceOf[ConstantType]) Literal(s.tpe.asInstanceOf[ConstantType].value)
149147
else t
150148
case _ => t
151149
}
150+
151+
case _ => t
152152
}
153153

154154
// This case can only be triggered when running Simplify before pattern matching:

compiler/test/dotty/tools/dotc/SimplifyTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ abstract class SimplifyTests(val optimise: Boolean) extends DottyBytecodeTest {
152152
|print(4)
153153
""")
154154

155-
@Test def TwoValConstantFold =
155+
@Test def twoValConstantFold =
156156
check(
157157
"""
158158
|val i = 3

0 commit comments

Comments
 (0)