Skip to content

Commit a370eed

Browse files
committed
Fix #2266: Do not replace constant type lazy vals with constant.
1 parent f20ca3d commit a370eed

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
427427
def constToLiteral(tree: Tree)(implicit ctx: Context): Tree = {
428428
val tree1 = ConstFold(tree)
429429
tree1.tpe.widenTermRefExpr match {
430-
case ConstantType(value) if isIdempotentExpr(tree1) => Literal(value)
430+
case ConstantType(value) if isIdempotentExpr(tree1) && !tree1.symbol.is(Lazy) => Literal(value)
431431
case _ => tree1
432432
}
433433
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
X
2+
Y
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
object Test {
3+
lazy val x: true = { println("X"); true }
4+
5+
def main(args: Array[String]): Unit = {
6+
lazy val y: true = { println("Y"); true }
7+
x
8+
y
9+
}
10+
}

0 commit comments

Comments
 (0)