From 1121ac470667897f2719c2aa3589bbe1dd9eab6a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 7 Jan 2021 14:31:07 +0100 Subject: [PATCH 1/2] Propagate missing position Fixes #10880 --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 3 ++- tests/run-macros/i10880/Dsl_1.scala | 9 +++++++++ tests/run-macros/i10880/MyQuoteMacro_1.scala | 11 +++++++++++ tests/run-macros/i10880/PullAst_1.scala | 9 +++++++++ tests/run-macros/i10880/Test_2.scala | 9 +++++++++ 5 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 tests/run-macros/i10880/Dsl_1.scala create mode 100644 tests/run-macros/i10880/MyQuoteMacro_1.scala create mode 100644 tests/run-macros/i10880/PullAst_1.scala create mode 100644 tests/run-macros/i10880/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index db6165ed5f2f..07649021a151 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -892,7 +892,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { else def argsSpan = trailing.map(_.span).foldLeft(arg.span)(_.union(_)) letBindUnless(TreeInfo.Pure, arg)(Block(trailing, _).withSpan(argsSpan)) - finish(seq(prefix, seq(leading, argInPlace))) + val blockSpan = (prefix ::: leading).map(_.span).foldLeft(argInPlace.span)(_.union(_)) + finish(seq(prefix, seq(leading, argInPlace))).withSpan(blockSpan) } } else tree diff --git a/tests/run-macros/i10880/Dsl_1.scala b/tests/run-macros/i10880/Dsl_1.scala new file mode 100644 index 000000000000..cdf937fa2907 --- /dev/null +++ b/tests/run-macros/i10880/Dsl_1.scala @@ -0,0 +1,9 @@ +trait Ent(name: String) +case class MyContent(key: String, value: String) +case class MyInsert(key: String) + +object Dsl { + inline def ent: Ent = new Ent("something") {} + extension (ent: Ent) + inline def content(inline ins: MyInsert) = MyContent(ins.key, "blah") +} diff --git a/tests/run-macros/i10880/MyQuoteMacro_1.scala b/tests/run-macros/i10880/MyQuoteMacro_1.scala new file mode 100644 index 000000000000..31576cc6fe63 --- /dev/null +++ b/tests/run-macros/i10880/MyQuoteMacro_1.scala @@ -0,0 +1,11 @@ +import scala.quoted._ + +case class MyQuoted(val ast: String, sub: String) + +object MyQuoteMacro { + inline def myquote(inline content: MyContent): MyQuoted = ${ MyQuoteMacro.apply('content) } + def apply(content: Expr[MyContent])(using Quotes): Expr[MyQuoted] = { + import quotes.reflect._ + '{ MyQuoted($content.key, null) } + } +} diff --git a/tests/run-macros/i10880/PullAst_1.scala b/tests/run-macros/i10880/PullAst_1.scala new file mode 100644 index 000000000000..7440ddf7a90d --- /dev/null +++ b/tests/run-macros/i10880/PullAst_1.scala @@ -0,0 +1,9 @@ +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/run-macros/i10880/Test_2.scala b/tests/run-macros/i10880/Test_2.scala new file mode 100644 index 000000000000..67833b7639e7 --- /dev/null +++ b/tests/run-macros/i10880/Test_2.scala @@ -0,0 +1,9 @@ +object Test { + import Dsl._ + + inline def q2 = MyQuoteMacro.myquote(ent.content(MyInsert("Foo"))) + + def main(args: Array[String]): Unit = { + println( PullAst.apply( q2 ) ) + } +} From 0d3bc590f98f496f1d14f398428136901f5f0e74 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 7 Jan 2021 16:53:12 +0100 Subject: [PATCH 2/2] Update compiler/src/dotty/tools/dotc/typer/Inliner.scala Co-authored-by: Fengyun Liu --- compiler/src/dotty/tools/dotc/typer/Inliner.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Inliner.scala b/compiler/src/dotty/tools/dotc/typer/Inliner.scala index 07649021a151..d704bcee3f1f 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inliner.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inliner.scala @@ -893,7 +893,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) { def argsSpan = trailing.map(_.span).foldLeft(arg.span)(_.union(_)) letBindUnless(TreeInfo.Pure, arg)(Block(trailing, _).withSpan(argsSpan)) val blockSpan = (prefix ::: leading).map(_.span).foldLeft(argInPlace.span)(_.union(_)) - finish(seq(prefix, seq(leading, argInPlace))).withSpan(blockSpan) + finish(seq(prefix, seq(leading, argInPlace)).withSpan(blockSpan)) } } else tree