Skip to content

Commit 32c8798

Browse files
committed
Fix constant folding during inlining
1 parent c68dc1f commit 32c8798

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import dotty.tools.dotc.ast.Trees._
44
import dotty.tools.dotc.ast.tpd
55
import dotty.tools.dotc.core.Contexts._
66
import dotty.tools.dotc.core.Phases.Phase
7-
import dotty.tools.dotc.typer.Inliner
7+
import dotty.tools.dotc.core.Types.MethodicType
8+
import dotty.tools.dotc.typer.{ConstFold, Inliner}
89

910

1011
class InlineCalls extends MacroTransform { thisPhase =>
@@ -22,14 +23,15 @@ class InlineCalls extends MacroTransform { thisPhase =>
2223

2324
class InlineCallsTransformer extends Transformer {
2425
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
25-
case _: RefTree | _: GenericApply[_] if Inliner.isInlineable(tree) && !ctx.reporter.hasErrors =>
26-
transform(Inliner.inlineCall(tree, tree.tpe.widen))
26+
case _: RefTree | _: GenericApply[_] if !tree.tpe.widenDealias.isInstanceOf[MethodicType] && Inliner.isInlineable(tree) && !ctx.reporter.hasErrors =>
27+
val tree2 = super.transform(tree) // transform arguments before inlining (inline arguments and constant fold arguments)
28+
transform(Inliner.inlineCall(tree2, tree.tpe.widen))
2729
case _: MemberDef =>
2830
val newTree = super.transform(tree)
2931
newTree.symbol.defTree = newTree // update tree set in PostTyper or set for inlined members
3032
newTree
3133
case _ =>
32-
super.transform(tree)
34+
ConstFold(super.transform(tree))
3335
}
3436
}
3537

0 commit comments

Comments
 (0)