From be19498c6f52d4a731a8b7014981b9c2aa8eb912 Mon Sep 17 00:00:00 2001 From: Anatolii Date: Thu, 3 Oct 2019 16:29:09 +0200 Subject: [PATCH] Fix #7342: Incorrectly setting sources for inlined lambdas on beta reduction On beta reduction of lambdas, we should create a block and not an inline node. --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 2 +- tests/pos-macros/i7342/Macro_1.scala | 5 +++++ tests/pos-macros/i7342/Macro_2.scala | 3 +++ tests/pos/i7342/First_1.scala | 1 + tests/pos/i7342/Second_2.scala | 1 + 5 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/pos-macros/i7342/Macro_1.scala create mode 100644 tests/pos-macros/i7342/Macro_2.scala create mode 100644 tests/pos/i7342/First_1.scala create mode 100644 tests/pos/i7342/Second_2.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 45e33741172f..284fe5f9cf2a 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -817,7 +817,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) { newOwners = ctx.owner :: Nil, substFrom = ddef.vparamss.head.map(_.symbol), substTo = argSyms) - Inlined(ddef, bindingsBuf.toList, expander.transform(ddef.rhs)) + Block(bindingsBuf.toList, expander.transform(ddef.rhs)) case _ => tree } case _ => tree diff --git a/tests/pos-macros/i7342/Macro_1.scala b/tests/pos-macros/i7342/Macro_1.scala new file mode 100644 index 000000000000..dcbeb4759678 --- /dev/null +++ b/tests/pos-macros/i7342/Macro_1.scala @@ -0,0 +1,5 @@ +import scala.quoted.{ QuoteContext, Expr } + +trait Foo + +inline def g(em: Expr[Foo])(using QuoteContext) = '{$em} diff --git a/tests/pos-macros/i7342/Macro_2.scala b/tests/pos-macros/i7342/Macro_2.scala new file mode 100644 index 000000000000..e51a08189301 --- /dev/null +++ b/tests/pos-macros/i7342/Macro_2.scala @@ -0,0 +1,3 @@ +import scala.quoted.{ QuoteContext, Expr } + +def h(m: Expr[Foo])(using QuoteContext): Expr[Any] = g(m) diff --git a/tests/pos/i7342/First_1.scala b/tests/pos/i7342/First_1.scala new file mode 100644 index 000000000000..94e7c0cf281c --- /dev/null +++ b/tests/pos/i7342/First_1.scala @@ -0,0 +1 @@ +inline def g(em: Int) = ((c: Int) => em).apply({println("AAAAAAA"); 1}) diff --git a/tests/pos/i7342/Second_2.scala b/tests/pos/i7342/Second_2.scala new file mode 100644 index 000000000000..e207ccd59ff0 --- /dev/null +++ b/tests/pos/i7342/Second_2.scala @@ -0,0 +1 @@ +def h(m: Int) = g(m)