diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-03-16 10:18:26 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-03-25 15:58:58 +0100 |
commit | f9a5880bf82b71174eb3dbd6b67646bbc27a975a (patch) | |
tree | cc622b21e2d32585eaa968bc82c2f7b7e20cc9f7 /test/files | |
parent | 49f54abed4f82d9b58f416915edaaea889734344 (diff) | |
download | scala-f9a5880bf82b71174eb3dbd6b67646bbc27a975a.tar.gz scala-f9a5880bf82b71174eb3dbd6b67646bbc27a975a.tar.bz2 scala-f9a5880bf82b71174eb3dbd6b67646bbc27a975a.zip |
introduces Mirror.typeOf
I just realized that our tag-based shortcuts were incomplete, because
they only work with root mirrors (doing just u.typeTag[T].tpe means that
the type is going to be resolved in u.rootMirror because that's the default).
This commit fixes this oversight. I'm hoping for 2.11.0-RC3, but also feel
free to reschedule to 2.12.0-M1 if it becomes clear that RC3 isn't happening.
Diffstat (limited to 'test/files')
-rw-r--r-- | test/files/run/mirror_symbolof_x.check | 13 | ||||
-rw-r--r-- | test/files/run/mirror_symbolof_x.scala | 43 |
2 files changed, 56 insertions, 0 deletions
diff --git a/test/files/run/mirror_symbolof_x.check b/test/files/run/mirror_symbolof_x.check new file mode 100644 index 0000000000..cc9cad7a13 --- /dev/null +++ b/test/files/run/mirror_symbolof_x.check @@ -0,0 +1,13 @@ +class Int +object C +type T +type Id +class Nothing +class Null +class Int +object C +type T +type Id +class Nothing +class Null +exception: class C not found. diff --git a/test/files/run/mirror_symbolof_x.scala b/test/files/run/mirror_symbolof_x.scala new file mode 100644 index 0000000000..8fec301f56 --- /dev/null +++ b/test/files/run/mirror_symbolof_x.scala @@ -0,0 +1,43 @@ +import scala.reflect.runtime.universe._ +import scala.reflect.runtime.{universe => ru} +import scala.reflect.runtime.{currentMirror => cm} +import scala.reflect.api.Mirror + +class C +object C + +object Test extends App { + object test1 { + val m = cm + type T = Int + type Id[X] = X + println(m.symbolOf[Int]: ru.TypeSymbol) + println(m.symbolOf[C.type]: ru.TypeSymbol) + println(m.symbolOf[T]: ru.TypeSymbol) + println(m.symbolOf[Id[_]]: ru.TypeSymbol) + println(m.symbolOf[Nothing]: ru.TypeSymbol) + println(m.symbolOf[Null]: ru.TypeSymbol) + } + + object test2 { + val m: Mirror[ru.type] = cm + type T = Int + type Id[X] = X + println(m.symbolOf[Int]: ru.TypeSymbol) + println(m.symbolOf[C.type]: ru.TypeSymbol) + println(m.symbolOf[T]: ru.TypeSymbol) + println(m.symbolOf[Id[_]]: ru.TypeSymbol) + println(m.symbolOf[Nothing]: ru.TypeSymbol) + println(m.symbolOf[Null]: ru.TypeSymbol) + } + + object test3 { + val m = ru.runtimeMirror(classOf[Int].getClass.getClassLoader) + try println(m.symbolOf[C]) + catch { case ex: ScalaReflectionException => println(s"exception: ${ex.getMessage}") } + } + + test1 + test2 + test3 +} |