Skip to content

Commit fc7bd7c

Browse files
committed
Fix rhs contantness.
1 parent 12d0189 commit fc7bd7c

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

compiler/src/dotty/tools/dotc/transform/Memoize.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ import Decorators._
9595
def adaptToField(tree: Tree) =
9696
if (tree.isEmpty) tree else tree.ensureConforms(field.info.widen)
9797

98+
val NoFieldNeeded = Lazy | Deferred | JavaDefined | (if (ctx.settings.YnoInline.value) EmptyFlags else Inline)
99+
98100
if (sym.is(Accessor, butNot = NoFieldNeeded))
99101
if (sym.isGetter) {
100102
var rhs = tree.rhs.changeOwnerAfter(sym, field, thisTransform)
@@ -112,5 +114,4 @@ import Decorators._
112114
// neither getters nor setters
113115
else tree
114116
}
115-
private val NoFieldNeeded = Lazy | Deferred | JavaDefined | Inline
116117
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,19 +1195,14 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
11951195
* see remark about idempotency in PostTyper#normalizeTree
11961196
*/
11971197
private def patchFinalVals(vdef: ValDef)(implicit ctx: Context): Unit = {
1198-
def skipBlocks(t: Tree): Tree = t match {
1199-
case Block(_, t1) => skipBlocks(t1)
1200-
case _ => t
1201-
}
12021198
def isFinalInlinableVal(sym: Symbol): Boolean = {
12031199
sym.is(Final, butNot = Mutable) &&
12041200
isIdempotentExpr(vdef.rhs) /* &&
12051201
ctx.scala2Mode (stay compatible with Scala2 for now) */
12061202
}
12071203
val sym = vdef.symbol
1208-
skipBlocks(vdef.rhs) match {
1209-
case lit: Literal if isFinalInlinableVal(sym) && !ctx.settings.YnoInline.value =>
1210-
sym.flags = sym.flags | Inline
1204+
sym.info match {
1205+
case info: ConstantType if isFinalInlinableVal(sym) && !ctx.settings.YnoInline.value => sym.setFlag(Inline)
12111206
case _ =>
12121207
}
12131208
}

0 commit comments

Comments
 (0)