Skip to content

Commit fc8f8fb

Browse files
Merge pull request #10780 from dotty-staging/fix-#10771
Fix #10771: Propagate missing span
2 parents 20f4e81 + 207cc20 commit fc8f8fb

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -891,7 +891,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
891891
val trailing = collectImpure(idx + 1, args.length)
892892
val argInPlace =
893893
if (trailing.isEmpty) arg
894-
else letBindUnless(TreeInfo.Pure, arg)(seq(trailing, _))
894+
else
895+
def argsSpan = trailing.map(_.span).foldLeft(arg.span)(_.union(_))
896+
letBindUnless(TreeInfo.Pure, arg)(Block(trailing, _).withSpan(argsSpan))
895897
finish(seq(prefix, seq(leading, argInPlace)))
896898
}
897899
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted._
2+
3+
case class MyQuoted(val ast: String, runtimeQuotes: List[String])
4+
5+
object MyQuoteMacro:
6+
inline def myquote: MyQuoted = ${ MyQuoteMacro.apply }
7+
def apply(using Quotes): Expr[MyQuoted] =
8+
'{ MyQuoted("p", ${Expr.ofList(List( '{ "foo" } ))}) }
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted._
2+
3+
object PullAst:
4+
def applyImpl(quoted: Expr[MyQuoted])(using qctx: Quotes): Expr[String] =
5+
'{ $quoted.ast.toString }
6+
inline def apply(inline quoted: MyQuoted): String =
7+
${ applyImpl('quoted) }

tests/pos-macros/i10771/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test:
2+
def main(args: Array[String]): Unit =
3+
println( PullAst.apply( MyQuoteMacro.myquote ) )

0 commit comments

Comments
 (0)