Skip to content

Commit 6368ae7

Browse files
committed
SI-7649 Fix positions for reshaped tag materializers
Calls to `materializeClassTag[T]` are replaced during reification with `implicitly[ClassTag[T]]` in the `reify` macro. This is done to avoid referring to symbols in scala-compiler.jar. Class- and Type-Tag materialization is treated in the same way. This commit positions the replacement trees to avoid triggering assertions under -Yrangepos.
1 parent 54cb6af commit 6368ae7

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

src/compiler/scala/reflect/reify/phases/Reshape.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,20 +91,20 @@ trait Reshape {
9191
private def undoMacroExpansion(tree: Tree): Tree =
9292
tree.attachments.get[MacroExpansionAttachment] match {
9393
case Some(MacroExpansionAttachment(original)) =>
94+
def mkImplicitly(tp: Type) = atPos(tree.pos)(
95+
gen.mkNullaryCall(Predef_implicitly, List(tp))
96+
)
97+
val sym = original.symbol
9498
original match {
9599
// this hack is necessary until I fix implicit macros
96100
// so far tag materialization is implemented by sneaky macros hidden in scala-compiler.jar
97101
// hence we cannot reify references to them, because noone will be able to see them later
98102
// when implicit macros are fixed, these sneaky macros will move to corresponding companion objects
99103
// of, say, ClassTag or TypeTag
100-
case Apply(TypeApply(_, List(tt)), _) if original.symbol == materializeClassTag =>
101-
gen.mkNullaryCall(Predef_implicitly, List(appliedType(ClassTagClass, tt.tpe)))
102-
case Apply(TypeApply(_, List(tt)), List(pre)) if original.symbol == materializeWeakTypeTag =>
103-
gen.mkNullaryCall(Predef_implicitly, List(typeRef(pre.tpe, WeakTypeTagClass, List(tt.tpe))))
104-
case Apply(TypeApply(_, List(tt)), List(pre)) if original.symbol == materializeTypeTag =>
105-
gen.mkNullaryCall(Predef_implicitly, List(typeRef(pre.tpe, TypeTagClass, List(tt.tpe))))
106-
case _ =>
107-
original
104+
case Apply(TypeApply(_, List(tt)), _) if sym == materializeClassTag => mkImplicitly(appliedType(ClassTagClass, tt.tpe))
105+
case Apply(TypeApply(_, List(tt)), List(pre)) if sym == materializeWeakTypeTag => mkImplicitly(typeRef(pre.tpe, WeakTypeTagClass, List(tt.tpe)))
106+
case Apply(TypeApply(_, List(tt)), List(pre)) if sym == materializeTypeTag => mkImplicitly(typeRef(pre.tpe, TypeTagClass, List(tt.tpe)))
107+
case _ => original
108108
}
109109
case _ => tree
110110
}

test/files/pos/t7649.flags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Yrangepos

test/files/pos/t7649.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
object Test {
2+
val c: reflect.macros.Context = ???
3+
import c.universe._
4+
reify {
5+
// The lookup of the implicit WeakTypeTag[Any]
6+
// was triggering an unpositioned tree.
7+
c.Expr[Any](Literal(Constant(0))).splice
8+
}
9+
10+
import scala.reflect.ClassTag
11+
def ct[A: ClassTag]: Expr[A] = ???
12+
def tt[A: TypeTag]: Expr[A] = ???
13+
def wtt[A: WeakTypeTag]: Expr[A] = ???
14+
15+
reify {
16+
ct[String].splice
17+
tt[String].splice
18+
wtt[String].splice
19+
}
20+
}

0 commit comments

Comments
 (0)