Skip to content

Commit 3b60a7a

Browse files
Merge pull request #11026 from dotty-staging/fix-#10880
Propagate missing position
2 parents 75ee5a0 + 0d3bc59 commit 3b60a7a

File tree

5 files changed

+40
-1
lines changed

5 files changed

+40
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -892,7 +892,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
892892
else
893893
def argsSpan = trailing.map(_.span).foldLeft(arg.span)(_.union(_))
894894
letBindUnless(TreeInfo.Pure, arg)(Block(trailing, _).withSpan(argsSpan))
895-
finish(seq(prefix, seq(leading, argInPlace)))
895+
val blockSpan = (prefix ::: leading).map(_.span).foldLeft(argInPlace.span)(_.union(_))
896+
finish(seq(prefix, seq(leading, argInPlace)).withSpan(blockSpan))
896897
}
897898
}
898899
else tree

tests/run-macros/i10880/Dsl_1.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Ent(name: String)
2+
case class MyContent(key: String, value: String)
3+
case class MyInsert(key: String)
4+
5+
object Dsl {
6+
inline def ent: Ent = new Ent("something") {}
7+
extension (ent: Ent)
8+
inline def content(inline ins: MyInsert) = MyContent(ins.key, "blah")
9+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.quoted._
2+
3+
case class MyQuoted(val ast: String, sub: String)
4+
5+
object MyQuoteMacro {
6+
inline def myquote(inline content: MyContent): MyQuoted = ${ MyQuoteMacro.apply('content) }
7+
def apply(content: Expr[MyContent])(using Quotes): Expr[MyQuoted] = {
8+
import quotes.reflect._
9+
'{ MyQuoted($content.key, null) }
10+
}
11+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.quoted._
2+
3+
object PullAst {
4+
def applyImpl(quoted: Expr[MyQuoted])(using qctx: Quotes): Expr[String] =
5+
'{ $quoted.ast.toString }
6+
7+
inline def apply(inline quoted: MyQuoted): String =
8+
${ applyImpl('quoted) }
9+
}

tests/run-macros/i10880/Test_2.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
object Test {
2+
import Dsl._
3+
4+
inline def q2 = MyQuoteMacro.myquote(ent.content(MyInsert("Foo")))
5+
6+
def main(args: Array[String]): Unit = {
7+
println( PullAst.apply( q2 ) )
8+
}
9+
}

0 commit comments

Comments
 (0)