From 207cc20a4e9258f8a1fe510208f6237bfb507e92 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 14 Dec 2020 09:29:02 +0100 Subject: [PATCH] Fix #10771: Propagate missing span --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 4 +++- tests/pos-macros/i10771/MacroA_1.scala | 8 ++++++++ tests/pos-macros/i10771/MacroB_1.scala | 7 +++++++ tests/pos-macros/i10771/Test_2.scala | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 tests/pos-macros/i10771/MacroA_1.scala create mode 100644 tests/pos-macros/i10771/MacroB_1.scala create mode 100644 tests/pos-macros/i10771/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 83a4ca37ab9d..83b1b158836c 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -891,7 +891,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { val trailing = collectImpure(idx + 1, args.length) val argInPlace = if (trailing.isEmpty) arg - else letBindUnless(TreeInfo.Pure, arg)(seq(trailing, _)) + else + def argsSpan = trailing.map(_.span).foldLeft(arg.span)(_.union(_)) + letBindUnless(TreeInfo.Pure, arg)(Block(trailing, _).withSpan(argsSpan)) finish(seq(prefix, seq(leading, argInPlace))) } } diff --git a/tests/pos-macros/i10771/MacroA_1.scala b/tests/pos-macros/i10771/MacroA_1.scala new file mode 100644 index 000000000000..88da14fe31ac --- /dev/null +++ b/tests/pos-macros/i10771/MacroA_1.scala @@ -0,0 +1,8 @@ +import scala.quoted._ + +case class MyQuoted(val ast: String, runtimeQuotes: List[String]) + +object MyQuoteMacro: + inline def myquote: MyQuoted = ${ MyQuoteMacro.apply } + def apply(using Quotes): Expr[MyQuoted] = + '{ MyQuoted("p", ${Expr.ofList(List( '{ "foo" } ))}) } diff --git a/tests/pos-macros/i10771/MacroB_1.scala b/tests/pos-macros/i10771/MacroB_1.scala new file mode 100644 index 000000000000..e9bfe73fb1a2 --- /dev/null +++ b/tests/pos-macros/i10771/MacroB_1.scala @@ -0,0 +1,7 @@ +import scala.quoted._ + +object PullAst: + def applyImpl(quoted: Expr[MyQuoted])(using qctx: Quotes): Expr[String] = + '{ $quoted.ast.toString } + inline def apply(inline quoted: MyQuoted): String = + ${ applyImpl('quoted) } diff --git a/tests/pos-macros/i10771/Test_2.scala b/tests/pos-macros/i10771/Test_2.scala new file mode 100644 index 000000000000..7777454cfc36 --- /dev/null +++ b/tests/pos-macros/i10771/Test_2.scala @@ -0,0 +1,3 @@ +object Test: + def main(args: Array[String]): Unit = + println( PullAst.apply( MyQuoteMacro.myquote ) )