Skip to content

Commit 4dc3a33

Browse files
committed
SI-7375 ClassTag for value class aliases
reifyRuntimeClass now always dealiases its argument prior to processing.
1 parent 9b310bc commit 4dc3a33

File tree

6 files changed

+50
-2
lines changed

6 files changed

+50
-2
lines changed

src/compiler/scala/reflect/reify/package.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,18 +45,21 @@ package object reify {
4545
def reifyType(global: Global)(typer: global.analyzer.Typer,universe: global.Tree, mirror: global.Tree, tpe: global.Type, concrete: Boolean = false): global.Tree =
4646
mkReifier(global)(typer, universe, mirror, tpe, concrete = concrete).reification.asInstanceOf[global.Tree]
4747

48-
def reifyRuntimeClass(global: Global)(typer0: global.analyzer.Typer, tpe: global.Type, concrete: Boolean = true): global.Tree = {
48+
def reifyRuntimeClass(global: Global)(typer0: global.analyzer.Typer, tpe0: global.Type, concrete: Boolean = true): global.Tree = {
4949
import global._
5050
import definitions._
5151
import analyzer.enclosingMacroPosition
5252

53+
// SI-7375
54+
val tpe = tpe0.dealiasWiden
55+
5356
if (tpe.isSpliceable) {
5457
val classTagInScope = typer0.resolveClassTag(enclosingMacroPosition, tpe, allowMaterialization = false)
5558
if (!classTagInScope.isEmpty) return Select(classTagInScope, nme.runtimeClass)
5659
if (concrete) throw new ReificationException(enclosingMacroPosition, "tpe %s is an unresolved spliceable type".format(tpe))
5760
}
5861

59-
tpe.normalize match {
62+
tpe match {
6063
case TypeRef(_, ArrayClass, componentTpe :: Nil) =>
6164
val componentErasure = reifyRuntimeClass(global)(typer0, componentTpe, concrete)
6265
gen.mkMethodCall(arrayClassMethod, List(componentErasure))

test/files/run/t7375a.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
C1
2+
C2
3+
C1
4+
C2

test/files/run/t7375a.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import scala.reflect.ClassTag
2+
3+
class C1(val n: Int) extends AnyVal
4+
class C2(val n: Int) extends AnyRef
5+
6+
object Test {
7+
type F1 = C1
8+
type F2 = C2
9+
10+
def main(args: Array[String]): Unit = {
11+
println(implicitly[ClassTag[C1]])
12+
println(implicitly[ClassTag[C2]])
13+
println(implicitly[ClassTag[F1]])
14+
println(implicitly[ClassTag[F2]])
15+
}
16+
}

test/files/run/t7375b.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Predef.this.classOf[C1]
2+
Predef.this.classOf[C2]
3+
Predef.this.classOf[C1]
4+
Predef.this.classOf[C2]

test/files/run/t7375b/Macros_1.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import language.experimental.macros
2+
import scala.reflect.macros.Context
3+
4+
class C1(val n: Int) extends AnyVal
5+
class C2(val n: Int) extends AnyRef
6+
7+
object Macros {
8+
type F1 = C1
9+
type F2 = C2
10+
11+
def foo = macro impl
12+
def impl(c: Context) = {
13+
import c.universe._
14+
def test[T: c.TypeTag] = reify(println(c.literal(c.reifyRuntimeClass(c.typeOf[T]).toString).splice)).tree
15+
def tests = Block(List(test[C1], test[C2], test[F1], test[F2]), Literal(Constant(())))
16+
c.Expr[Unit](tests)
17+
}
18+
}

test/files/run/t7375b/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test extends App {
2+
Macros.foo
3+
}

0 commit comments

Comments
 (0)