Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

Fixed SI-6076. Range positions for macro-based string interpolation.

Should bring back the jenkins job as well.

Review by @odersky.
  • Loading branch information...
commit 72de4d83490190cec97fa56cfc5c18af6bb355d1 1 parent 0cfd858
@hubertp hubertp authored
2  src/compiler/scala/tools/reflect/FastTrack.scala
@@ -43,7 +43,7 @@ trait FastTrack {
ApiUniverseReify bindTo { case (c, Apply(TypeApply(_, List(tt)), List(expr))) => c.materializeExpr(c.prefix.tree, EmptyTree, expr) }
MacroContextReify bindTo { case (c, Apply(TypeApply(_, List(tt)), List(expr))) => c.materializeExprForMacroContext(c.prefix.tree, expr) }
ReflectRuntimeCurrentMirror bindTo { case (c, _) => scala.reflect.runtime.Macros.currentMirror(c).tree }
- StringContext_f bindTo { case (c, Apply(Select(Apply(_, parts), _), args)) => c.macro_StringInterpolation_f(parts, args) }
+ StringContext_f bindTo { case (c, app@Apply(Select(Apply(_, parts), _), args)) => c.macro_StringInterpolation_f(parts, args, app.pos) }
9 src/compiler/scala/tools/reflect/MacroImplementations.scala
@@ -8,9 +8,9 @@ import scala.collection.mutable.Stack
abstract class MacroImplementations {
val c: Context
- import c.universe._
+ import c.universe.{Position => SPosition, _}
@xeno-by Owner
xeno-by added a note

What does SPosition mean?

@hubertp Owner
hubertp added a note

I was getting ambiguous Positions. One from universe (which is the one I wanted) and for some reason one from FrontEnds (can we avoid it in the future somehow?)

@hubertp Owner
hubertp added a note

oh, and SPosition => ScalaPosition, maybe TreePosition would sound better? Doesn't really matter in the end I think.

@xeno-by Owner
xeno-by added a note

Aha I see. Possibly isn't the best place to put macro implementations. We do need to mix FrontEnds into tools.reflect.package, so that people can create reporters for their toolboxes. On the other hand macro context has its own Position (it maps to the same, but the interface is abstract). Hence the conflict.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
- def macro_StringInterpolation_f(parts: List[Tree], args: List[Tree]): Tree = {
+ def macro_StringInterpolation_f(parts: List[Tree], args: List[Tree], origApplyPos: SPosition): Tree = {
// the parts all have the same position information (as the expression is generated by the compiler)
// the args have correct position information
@@ -25,7 +25,6 @@ abstract class MacroImplementations {
"too many arguments for interpolated string")
val stringParts = parts map {
case Literal(Constant(s: String)) => s;
case _ => throw new IllegalArgumentException("argument parts must be a list of string literals")
@@ -39,7 +38,7 @@ abstract class MacroImplementations {
def defval(value: Tree, tpe: Type): Unit = {
val freshName = newTermName(c.fresh("arg$"))
- evals += ValDef(Modifiers(), freshName, TypeTree(tpe), value)
+ evals += ValDef(Modifiers(), freshName, TypeTree(tpe) setPos value.pos.focus, value) setPos value.pos
ids += Ident(freshName)
@@ -141,7 +140,7 @@ abstract class MacroImplementations {
List(ids: _* )
- Block(evals.toList, expr)
+ Block(evals.toList, atPos(origApplyPos.focus)(expr)) setPos origApplyPos.makeTransparent

0 comments on commit 72de4d8

Please sign in to comment.
Something went wrong with that request. Please try again.