Skip to content

Fix #10771: Propagate missing span #10780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -891,7 +891,9 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
val trailing = collectImpure(idx + 1, args.length)
val argInPlace =
if (trailing.isEmpty) arg
else letBindUnless(TreeInfo.Pure, arg)(seq(trailing, _))
else
def argsSpan = trailing.map(_.span).foldLeft(arg.span)(_.union(_))
letBindUnless(TreeInfo.Pure, arg)(Block(trailing, _).withSpan(argsSpan))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this logic can be moved to letBindUnless. Maybe add a TODO here.

Copy link
Contributor Author

@nicolasstucki nicolasstucki Dec 14, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be more expensive to do it in letBindUnless. So far I've only seen this happened once inside a letBindUnless.

finish(seq(prefix, seq(leading, argInPlace)))
}
}
Expand Down
8 changes: 8 additions & 0 deletions tests/pos-macros/i10771/MacroA_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import scala.quoted._

case class MyQuoted(val ast: String, runtimeQuotes: List[String])

object MyQuoteMacro:
inline def myquote: MyQuoted = ${ MyQuoteMacro.apply }
def apply(using Quotes): Expr[MyQuoted] =
'{ MyQuoted("p", ${Expr.ofList(List( '{ "foo" } ))}) }
7 changes: 7 additions & 0 deletions tests/pos-macros/i10771/MacroB_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted._

object PullAst:
def applyImpl(quoted: Expr[MyQuoted])(using qctx: Quotes): Expr[String] =
'{ $quoted.ast.toString }
inline def apply(inline quoted: MyQuoted): String =
${ applyImpl('quoted) }
3 changes: 3 additions & 0 deletions tests/pos-macros/i10771/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test:
def main(args: Array[String]): Unit =
println( PullAst.apply( MyQuoteMacro.myquote ) )