From ea9325965a82610083e75e0d111fe3d70c46b3d2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 17 Apr 2017 16:54:44 +0200 Subject: Only allow constant type vals to be inlined. --- compiler/src/dotty/tools/dotc/ast/TreeInfo.scala | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'compiler') diff --git a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala index 46af1f1b4..49187492e 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeInfo.scala @@ -427,11 +427,12 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] => def constToLiteral(tree: Tree)(implicit ctx: Context): Tree = { val tree1 = ConstFold(tree) def canInlineConstant(value: Constant): Boolean = { + val sym = tree1.symbol isIdempotentExpr(tree1) && // see note in documentation // lazy value must be initialized (would not be needed with isPureExpr) - !tree1.symbol.is(Lazy) && + !sym.is(Lazy) && // could hide initialization order issues (ex. val with constant type read before initialized) - (!ctx.owner.isLocalDummy || (tree1.symbol.is(Method) || value.isZero) || + (!ctx.owner.isLocalDummy || (!sym.is(Method) && !sym.is(Lazy) && value.isZero) || ctx.scala2Mode // ignore in Scala 2 because of inlined `final val` values ) } -- cgit v1.2.3