Skip to content

Commit c9f4964

Browse files
committed
Fix #8325: Add missing span
1 parent 5374d91 commit c9f4964

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed

compiler/src/dotty/tools/dotc/transform/localopt/StringInterpolatorOpt.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class StringInterpolatorOpt extends MiniPhase {
101101
val elemi = elems.iterator
102102
var result: Tree = stri.next
103103
def concat(tree: Tree): Unit = {
104-
result = result.select(defn.String_+).appliedTo(tree)
104+
result = result.select(defn.String_+).appliedTo(tree).withSpan(tree.span)
105105
}
106106
while (elemi.hasNext) {
107107
concat(elemi.next)

tests/pos-macros/i8325/Macro_1.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package a
2+
3+
import scala.quoted._
4+
import scala.quoted.matching._
5+
6+
object A:
7+
8+
inline def transform[A](inline expr: A): A = ${
9+
transformImplExpr('expr)
10+
}
11+
12+
def pure[A](a:A):A = ???
13+
14+
def transformImplExpr[A:Type](using qctx: QuoteContext)(expr: Expr[A]): Expr[A] = {
15+
import qctx.tasty.{given _, _}
16+
expr.unseal match {
17+
case Inlined(x,y,z) => transformImplExpr(z.seal.asInstanceOf[Expr[A]])
18+
case Apply(fun,args) => '{ A.pure(${Apply(fun,args).seal.asInstanceOf[Expr[A]]}) }
19+
case other => expr
20+
}
21+
}

tests/pos-macros/i8325/Test_2.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package a
2+
3+
class Test1 {
4+
5+
def t1(): Unit = {
6+
A.transform(
7+
s"a ${1} ${2}")
8+
}
9+
10+
}

tests/pos-macros/i8325b/Macro_1.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package a
2+
3+
import scala.quoted._
4+
import scala.quoted.matching._
5+
6+
object A:
7+
8+
inline def transform[A](inline expr: A): A = ${
9+
transformImplExpr('expr)
10+
}
11+
12+
def pure[A](a:A):A = ???
13+
14+
def transformImplExpr[A:Type](using qctx: QuoteContext)(expr: Expr[A]): Expr[A] = {
15+
import qctx.tasty.{given _, _}
16+
expr.unseal match {
17+
case Inlined(x,y,z) => transformImplExpr(z.seal.asInstanceOf[Expr[A]])
18+
case r@Apply(fun,args) => '{
19+
A.pure(${r.seal.asInstanceOf[Expr[A]]}) }
20+
case other => expr
21+
}
22+
}

tests/pos-macros/i8325b/Test_2.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package a
2+
3+
class Test1 {
4+
5+
def t1(): Unit = {
6+
A.transform(
7+
s"a ${1} ${2}")
8+
}
9+
10+
}

0 commit comments

Comments
 (0)