diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2013-05-31 23:03:25 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2013-05-31 23:03:25 +0200 |
commit | 4dc3a3319705ba9cdf63978bbed9a2fc8051b34f (patch) | |
tree | c7b36ccf679cc8496a1af9ac1c8a7a35458b5f17 | |
parent | 9b310bc906257724fb0772cee116e4a7ebdb0acb (diff) | |
download | scala-4dc3a3319705ba9cdf63978bbed9a2fc8051b34f.tar.gz scala-4dc3a3319705ba9cdf63978bbed9a2fc8051b34f.tar.bz2 scala-4dc3a3319705ba9cdf63978bbed9a2fc8051b34f.zip |
SI-7375 ClassTag for value class aliases
reifyRuntimeClass now always dealiases its argument prior to processing.
-rw-r--r-- | src/compiler/scala/reflect/reify/package.scala | 7 | ||||
-rw-r--r-- | test/files/run/t7375a.check | 4 | ||||
-rw-r--r-- | test/files/run/t7375a.scala | 16 | ||||
-rw-r--r-- | test/files/run/t7375b.check | 4 | ||||
-rw-r--r-- | test/files/run/t7375b/Macros_1.scala | 18 | ||||
-rw-r--r-- | test/files/run/t7375b/Test_2.scala | 3 |
6 files changed, 50 insertions, 2 deletions
diff --git a/src/compiler/scala/reflect/reify/package.scala b/src/compiler/scala/reflect/reify/package.scala index 55f8684df2..6777bb0a50 100644 --- a/src/compiler/scala/reflect/reify/package.scala +++ b/src/compiler/scala/reflect/reify/package.scala @@ -45,18 +45,21 @@ package object reify { def reifyType(global: Global)(typer: global.analyzer.Typer,universe: global.Tree, mirror: global.Tree, tpe: global.Type, concrete: Boolean = false): global.Tree = mkReifier(global)(typer, universe, mirror, tpe, concrete = concrete).reification.asInstanceOf[global.Tree] - def reifyRuntimeClass(global: Global)(typer0: global.analyzer.Typer, tpe: global.Type, concrete: Boolean = true): global.Tree = { + def reifyRuntimeClass(global: Global)(typer0: global.analyzer.Typer, tpe0: global.Type, concrete: Boolean = true): global.Tree = { import global._ import definitions._ import analyzer.enclosingMacroPosition + // SI-7375 + val tpe = tpe0.dealiasWiden + if (tpe.isSpliceable) { val classTagInScope = typer0.resolveClassTag(enclosingMacroPosition, tpe, allowMaterialization = false) if (!classTagInScope.isEmpty) return Select(classTagInScope, nme.runtimeClass) if (concrete) throw new ReificationException(enclosingMacroPosition, "tpe %s is an unresolved spliceable type".format(tpe)) } - tpe.normalize match { + tpe match { case TypeRef(_, ArrayClass, componentTpe :: Nil) => val componentErasure = reifyRuntimeClass(global)(typer0, componentTpe, concrete) gen.mkMethodCall(arrayClassMethod, List(componentErasure)) diff --git a/test/files/run/t7375a.check b/test/files/run/t7375a.check new file mode 100644 index 0000000000..a0a15dfb2f --- /dev/null +++ b/test/files/run/t7375a.check @@ -0,0 +1,4 @@ +C1 +C2 +C1 +C2 diff --git a/test/files/run/t7375a.scala b/test/files/run/t7375a.scala new file mode 100644 index 0000000000..e46ad08f63 --- /dev/null +++ b/test/files/run/t7375a.scala @@ -0,0 +1,16 @@ +import scala.reflect.ClassTag + +class C1(val n: Int) extends AnyVal +class C2(val n: Int) extends AnyRef + +object Test { + type F1 = C1 + type F2 = C2 + + def main(args: Array[String]): Unit = { + println(implicitly[ClassTag[C1]]) + println(implicitly[ClassTag[C2]]) + println(implicitly[ClassTag[F1]]) + println(implicitly[ClassTag[F2]]) + } +} diff --git a/test/files/run/t7375b.check b/test/files/run/t7375b.check new file mode 100644 index 0000000000..d7578e28ba --- /dev/null +++ b/test/files/run/t7375b.check @@ -0,0 +1,4 @@ +Predef.this.classOf[C1] +Predef.this.classOf[C2] +Predef.this.classOf[C1] +Predef.this.classOf[C2] diff --git a/test/files/run/t7375b/Macros_1.scala b/test/files/run/t7375b/Macros_1.scala new file mode 100644 index 0000000000..70e79cc2b4 --- /dev/null +++ b/test/files/run/t7375b/Macros_1.scala @@ -0,0 +1,18 @@ +import language.experimental.macros +import scala.reflect.macros.Context + +class C1(val n: Int) extends AnyVal +class C2(val n: Int) extends AnyRef + +object Macros { + type F1 = C1 + type F2 = C2 + + def foo = macro impl + def impl(c: Context) = { + import c.universe._ + def test[T: c.TypeTag] = reify(println(c.literal(c.reifyRuntimeClass(c.typeOf[T]).toString).splice)).tree + def tests = Block(List(test[C1], test[C2], test[F1], test[F2]), Literal(Constant(()))) + c.Expr[Unit](tests) + } +}
\ No newline at end of file diff --git a/test/files/run/t7375b/Test_2.scala b/test/files/run/t7375b/Test_2.scala new file mode 100644 index 0000000000..acfddae942 --- /dev/null +++ b/test/files/run/t7375b/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Macros.foo +}
\ No newline at end of file |