Skip to content

Commit 06744dc

Browse files
committed
Fix illegal positions being generated in SpliceInterpter
1 parent 7328cd6 commit 06744dc

File tree

5 files changed

+26
-1
lines changed

5 files changed

+26
-1
lines changed

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ object Splicer {
256256
case tree: Inlined if tree.inlinedFromOuterScope => tree.expansion
257257
case _ => body
258258
}
259-
new ExprImpl(Inlined(EmptyTree, Nil, QuoteUtils.changeOwnerOfTree(body1, ctx.owner)).withSpan(body1.span), SpliceScope.getCurrent)
259+
new ExprImpl(Inlined(EmptyTree, Nil, QuoteUtils.changeOwnerOfTree(body1, ctx.owner)).cloneIn(body1.source).withSpan(body1.span), SpliceScope.getCurrent)
260260

261261
// Interpret level -1 `Type.of[T]`
262262
case Apply(TypeApply(fn, quoted :: Nil), _) if fn.symbol == defn.QuotedTypeModule_of =>

tests/run-macros/i21910.check

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
70..71 of tests/run-macros/i21910/Outer.scala with length 73
2+
70..71 of tests/run-macros/i21910/Outer.scala with length 73
3+
44..57 of tests/run-macros/i21910/Main.scala with length 58

tests/run-macros/i21910/Inner.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.quoted.*
2+
3+
object Inner:
4+
inline def pos(inline x: Any): Unit =
5+
${ posImpl('x) }
6+
7+
def posImpl(x: Expr[Any])(using Quotes): Expr[Unit] =
8+
import quotes.reflect.*
9+
def printPos(p: Position): Expr[Unit] =
10+
val str = Expr(s"${p.start}..${p.end} of ${p.sourceFile.path} with length ${p.sourceFile.content.get.length}")
11+
'{println($str)}
12+
'{
13+
${printPos(x.asTerm.pos)}
14+
${printPos(x.asTerm.asInstanceOf[Inlined].body.pos)}
15+
${printPos(x.asTerm.asInstanceOf[Inlined].body.asInstanceOf[Inlined].body.pos)}
16+
}

tests/run-macros/i21910/Main.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
@main def Test(): Unit =
2+
Outer.outer:
3+
println("hi")

tests/run-macros/i21910/Outer.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Outer:
2+
inline def outer(inline x: Any): Unit =
3+
Inner.pos(x)

0 commit comments

Comments
 (0)