aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Stucki <nicolas.stucki@gmail.com>2017-04-15 19:29:44 +0200
committerNicolas Stucki <nicolas.stucki@gmail.com>2017-04-15 19:36:44 +0200
commita370eed7bebbc534e19de7dadefd72a70349854f (patch)
treec246d5be1e1e94ef4b0ac4860af722613c56e1b3
parentf20ca3d358c650f6a58528018aa7d848b1f6a28f (diff)
downloaddotty-a370eed7bebbc534e19de7dadefd72a70349854f.zip
dotty-a370eed7bebbc534e19de7dadefd72a70349854f.tar.gz
dotty-a370eed7bebbc534e19de7dadefd72a70349854f.tar.bz2
Fix #2266: Do not replace constant type lazy vals with constant.
-rw-r--r--compiler/src/dotty/tools/dotc/ast/TreeInfo.scala2
-rw-r--r--tests/run/inline-constant-lazy-val.check2
-rw-r--r--tests/run/inline-constant-lazy-val.scala10
3 files changed, 13 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
index f3bce40..cac0e4b 100644
--- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
+++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
@@ -427,7 +427,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
def constToLiteral(tree: Tree)(implicit ctx: Context): Tree = {
val tree1 = ConstFold(tree)
tree1.tpe.widenTermRefExpr match {
- case ConstantType(value) if isIdempotentExpr(tree1) => Literal(value)
+ case ConstantType(value) if isIdempotentExpr(tree1) && !tree1.symbol.is(Lazy) => Literal(value)
case _ => tree1
}
}
diff --git a/tests/run/inline-constant-lazy-val.check b/tests/run/inline-constant-lazy-val.check
new file mode 100644
index 0000000..16858db
--- /dev/null
+++ b/tests/run/inline-constant-lazy-val.check
@@ -0,0 +1,2 @@
+X
+Y
diff --git a/tests/run/inline-constant-lazy-val.scala b/tests/run/inline-constant-lazy-val.scala
new file mode 100644
index 0000000..5f4aaa1
--- /dev/null
+++ b/tests/run/inline-constant-lazy-val.scala
@@ -0,0 +1,10 @@
+
+object Test {
+ lazy val x: true = { println("X"); true }
+
+ def main(args: Array[String]): Unit = {
+ lazy val y: true = { println("Y"); true }
+ x
+ y
+ }
+} \ No newline at end of file