From c9f4964a10ad8a585a403911493e6782e304623c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 17 Feb 2020 11:27:23 +0100 Subject: [PATCH] Fix #8325: Add missing span --- .../localopt/StringInterpolatorOpt.scala | 2 +- tests/pos-macros/i8325/Macro_1.scala | 21 ++++++++++++++++++ tests/pos-macros/i8325/Test_2.scala | 10 +++++++++ tests/pos-macros/i8325b/Macro_1.scala | 22 +++++++++++++++++++ tests/pos-macros/i8325b/Test_2.scala | 10 +++++++++ 5 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 tests/pos-macros/i8325/Macro_1.scala create mode 100644 tests/pos-macros/i8325/Test_2.scala create mode 100644 tests/pos-macros/i8325b/Macro_1.scala create mode 100644 tests/pos-macros/i8325b/Test_2.scala diff --git a/compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala b/compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala index 962cb0e2e648..738b01883d5f 100644 --- a/compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala +++ b/compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala @@ -101,7 +101,7 @@ class StringInterpolatorOpt extends MiniPhase { val elemi = elems.iterator var result: Tree = stri.next def concat(tree: Tree): Unit = { - result = result.select(defn.String_+).appliedTo(tree) + result = result.select(defn.String_+).appliedTo(tree).withSpan(tree.span) } while (elemi.hasNext) { concat(elemi.next) diff --git a/tests/pos-macros/i8325/Macro_1.scala b/tests/pos-macros/i8325/Macro_1.scala new file mode 100644 index 000000000000..f2f85c8746e0 --- /dev/null +++ b/tests/pos-macros/i8325/Macro_1.scala @@ -0,0 +1,21 @@ +package a + +import scala.quoted._ +import scala.quoted.matching._ + +object A: + + inline def transform[A](inline expr: A): A = ${ + transformImplExpr('expr) + } + + def pure[A](a:A):A = ??? + + def transformImplExpr[A:Type](using qctx: QuoteContext)(expr: Expr[A]): Expr[A] = { + import qctx.tasty.{given _, _} + expr.unseal match { + case Inlined(x,y,z) => transformImplExpr(z.seal.asInstanceOf[Expr[A]]) + case Apply(fun,args) => '{ A.pure(${Apply(fun,args).seal.asInstanceOf[Expr[A]]}) } + case other => expr + } + } diff --git a/tests/pos-macros/i8325/Test_2.scala b/tests/pos-macros/i8325/Test_2.scala new file mode 100644 index 000000000000..8b0a74b11a08 --- /dev/null +++ b/tests/pos-macros/i8325/Test_2.scala @@ -0,0 +1,10 @@ +package a + +class Test1 { + + def t1(): Unit = { + A.transform( + s"a ${1} ${2}") + } + +} diff --git a/tests/pos-macros/i8325b/Macro_1.scala b/tests/pos-macros/i8325b/Macro_1.scala new file mode 100644 index 000000000000..a2f5a101b09a --- /dev/null +++ b/tests/pos-macros/i8325b/Macro_1.scala @@ -0,0 +1,22 @@ +package a + +import scala.quoted._ +import scala.quoted.matching._ + +object A: + + inline def transform[A](inline expr: A): A = ${ + transformImplExpr('expr) + } + + def pure[A](a:A):A = ??? + + def transformImplExpr[A:Type](using qctx: QuoteContext)(expr: Expr[A]): Expr[A] = { + import qctx.tasty.{given _, _} + expr.unseal match { + case Inlined(x,y,z) => transformImplExpr(z.seal.asInstanceOf[Expr[A]]) + case r@Apply(fun,args) => '{ + A.pure(${r.seal.asInstanceOf[Expr[A]]}) } + case other => expr + } + } diff --git a/tests/pos-macros/i8325b/Test_2.scala b/tests/pos-macros/i8325b/Test_2.scala new file mode 100644 index 000000000000..8b0a74b11a08 --- /dev/null +++ b/tests/pos-macros/i8325b/Test_2.scala @@ -0,0 +1,10 @@ +package a + +class Test1 { + + def t1(): Unit = { + A.transform( + s"a ${1} ${2}") + } + +}