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...
1 parent 0cfd858 commit 72de4d83490190cec97fa56cfc5c18af6bb355d1 @hubertp hubertp committed Jul 17, 2012
View
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) }
registry
}
}
View
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
The Scala Programming Language member
xeno-by added a line comment Jul 18, 2012

What does SPosition mean?

@hubertp
The Scala Programming Language member
hubertp added a line comment Jul 18, 2012

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
The Scala Programming Language member
hubertp added a line comment Jul 18, 2012

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

@xeno-by
The Scala Programming Language member
xeno-by added a line comment Jul 18, 2012

Aha I see. Possibly scala.tools.reflect 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 scala.tools.nsc.Position, 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 {
c.abort(args(parts.length-1).pos,
"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.