diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-28 12:05:34 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-14 14:09:17 +0100 |
commit | ada0252d4494611904c15cc5da72654c1a180a8f (patch) | |
tree | 662e972fdf295e57bdb5bcc6b47aafec7a242ea8 /test | |
parent | b0176294060c9ce8b86d71e7bc8a7a13cef15b1e (diff) | |
download | scala-ada0252d4494611904c15cc5da72654c1a180a8f.tar.gz scala-ada0252d4494611904c15cc5da72654c1a180a8f.tar.bz2 scala-ada0252d4494611904c15cc5da72654c1a180a8f.zip |
SI-8194 adds Universe.symbolOf[T]
A very frequent use for a result of typeOf is obtaining an underlying
type symbol. Another thing that comes up occasionally at stack overflow
is a request to add facilities for reification of symbols.
This naturally suggests that our reflection API would benefit from a method
called symbolOf that can take a term or type argument and return an underlying
symbol.
While an API to extract a term symbol from an expression needs some time
to be designed and then implemented robustly (we don’t have untyped macros
so we’ll have to account for various desugarings), meaning that we probably
won’t have time for that in 2.11, a type symbol extractor seems to be
a very low-hanging fruit.
Diffstat (limited to 'test')
-rw-r--r-- | test/files/run/typetags_symbolof_x.check | 6 | ||||
-rw-r--r-- | test/files/run/typetags_symbolof_x.scala | 15 |
2 files changed, 21 insertions, 0 deletions
diff --git a/test/files/run/typetags_symbolof_x.check b/test/files/run/typetags_symbolof_x.check new file mode 100644 index 0000000000..fd0e069bca --- /dev/null +++ b/test/files/run/typetags_symbolof_x.check @@ -0,0 +1,6 @@ +class Int +object C +type T +type Id +class Nothing +class Null diff --git a/test/files/run/typetags_symbolof_x.scala b/test/files/run/typetags_symbolof_x.scala new file mode 100644 index 0000000000..333c4e7da4 --- /dev/null +++ b/test/files/run/typetags_symbolof_x.scala @@ -0,0 +1,15 @@ +import scala.reflect.runtime.universe._ + +class C +object C + +object Test extends App { + type T = Int + type Id[X] = X + println(symbolOf[Int]) + println(symbolOf[C.type]) + println(symbolOf[T]) + println(symbolOf[Id[_]]) + println(symbolOf[Nothing]) + println(symbolOf[Null]) +} |