Skip to content

Commit 048181d

Browse files
committed
Fix reporter position
1 parent 86a2aa6 commit 048181d

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class Interpreter(implicit ctx: Context) {
6262
*
6363
* If some error is encountered while interpreting a ctx.error is emitted and a StopInterpretation is thrown.
6464
*/
65-
private def interpretTreeImpl(tree: Tree, env: Env): Object = {
65+
protected def interpretTreeImpl(tree: Tree, env: Env): Object = {
6666
// println(s"Interpreting:\n${tree.show}\n$env\n")
6767

6868
implicit val pos: Position = tree.pos
@@ -72,12 +72,6 @@ class Interpreter(implicit ctx: Context) {
7272
if (quotedTree.isTerm) new scala.quoted.Exprs.TreeExpr(quotedTree)
7373
else new scala.quoted.Types.TreeType(quotedTree)
7474

75-
case tree: RefTree if tree.symbol eq defn.QuotedReporterDummy =>
76-
new scala.quoted.Reporter {
77-
override def error(message: String): Unit = ctx.error(message, pos)
78-
override def warn(message: String): Unit = ctx.warning(message, pos)
79-
}
80-
8175
case Literal(Constant(c)) => c.asInstanceOf[Object]
8276

8377
case Apply(fn, args) if fn.symbol.isConstructor =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
336336
}
337337

338338
val tree1 =
339-
if (level == 0) cpy.Inlined(tree)(call, stagedBindings, Splicer.splice(seq(splicedBindings, body)))
339+
if (level == 0) cpy.Inlined(tree)(call, stagedBindings, Splicer.splice(seq(splicedBindings, body).withPos(tree.pos)))
340340
else seq(stagedBindings, cpy.Select(expansion)(cpy.Inlined(tree)(call, splicedBindings, body), name))
341341
val tree2 = transform(tree1)
342342

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

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@ package transform
33

44
import dotty.tools.dotc.ast.tpd
55
import dotty.tools.dotc.core.Contexts._
6+
import dotty.tools.dotc.core.Decorators._
7+
import dotty.tools.dotc.core.Symbols._
68
import dotty.tools.dotc.core.quoted._
79
import dotty.tools.dotc.interpreter._
10+
import dotty.tools.dotc.util.SourcePosition
811

912
/** Utility class to splice quoted expressions */
1013
object Splicer {
@@ -20,9 +23,18 @@ object Splicer {
2023
}
2124

2225
/** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */
23-
private def reflectiveSplice(tree: Tree)(implicit ctx: Context): Tree = {
24-
val interpreter = new Interpreter
25-
interpreter.interpretTree[scala.quoted.Expr[_]](tree).map(PickledQuotes.quotedExprToTree).getOrElse(tree)
26+
private def reflectiveSplice(tree0: Tree)(implicit ctx: Context): Tree = {
27+
val interpreter = new Interpreter {
28+
override protected def interpretTreeImpl(tree: Tree, env: Env): AnyRef = tree match {
29+
case tree: RefTree if tree.symbol eq defn.QuotedReporterDummy => new Reporter(tree0.pos, ctx)
30+
case _ => super.interpretTreeImpl(tree, env)
31+
}
32+
}
33+
interpreter.interpretTree[scala.quoted.Expr[_]](tree0).map(PickledQuotes.quotedExprToTree).getOrElse(tree0)
2634
}
2735

36+
private class Reporter(pos: SourcePosition, ctx: Context) extends scala.quoted.Reporter {
37+
override def error(message: String): Unit = ctx.error(message, pos)
38+
override def warn(message: String): Unit = ctx.warning(message, pos)
39+
}
2840
}

0 commit comments

Comments
 (0)