diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index aea9129959d1..d0d03532b977 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -1219,6 +1219,15 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { super.typedIf(if1, pt) } + override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree = + val vdef1 = + if sym.is(Inline) then + val rhs = typed(vdef.rhs) + sym.info = rhs.tpe + untpd.cpy.ValDef(vdef)(vdef.name, untpd.TypeTree(rhs.tpe), untpd.TypedSplice(rhs)) + else vdef + super.typedValDef(vdef1, sym) + override def typedApply(tree: untpd.Apply, pt: Type)(using Context): Tree = constToLiteral(betaReduce(super.typedApply(tree, pt))) match { case res: Apply if res.symbol == defn.InternalQuoted_exprSplice diff --git a/tests/pos/i8842a.scala b/tests/pos/i8842a.scala new file mode 100644 index 000000000000..49da473a3878 --- /dev/null +++ b/tests/pos/i8842a.scala @@ -0,0 +1,5 @@ +inline def f(inline x: Int): Unit = { + inline val twice = x + x +} + +def test: Unit = f(3) diff --git a/tests/pos/i8842b.scala b/tests/pos/i8842b.scala new file mode 100644 index 000000000000..cd76bd180e5f --- /dev/null +++ b/tests/pos/i8842b.scala @@ -0,0 +1,8 @@ +inline def f(inline x: Int): Unit = { + inline val twice = x + x + inline val thrice = twice + x + val res = thrice + res +} + +def test: Unit = f(3)