diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-12-10 00:33:30 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-14 14:09:14 +0100 |
commit | b0176294060c9ce8b86d71e7bc8a7a13cef15b1e (patch) | |
tree | fb68701eda408edfd8d347d22ca97f36eb70df45 /test/files/run/reify_typeof.check | |
parent | 51b16e421ddd4e6c7e90ba945addf39ffcb4fa41 (diff) | |
download | scala-b0176294060c9ce8b86d71e7bc8a7a13cef15b1e.tar.gz scala-b0176294060c9ce8b86d71e7bc8a7a13cef15b1e.tar.bz2 scala-b0176294060c9ce8b86d71e7bc8a7a13cef15b1e.zip |
SI-6484 adds Universe.typeOf[T](x: T)
This is a nice addition to Universe.typeOf[T], quite frequently useful
for inspecting ad-hoc types.
As promised by https://github.com/scala/scala/pull/1741, which represented
my previous stab at adding this API, I ran into problems when trying to
introduce the API naively.
def typeOf[T](implicit ttag: TypeTag[T]): Type
def typeOf[T: TypeTag](x: T): Type
The first problem came from the fact that even though they don't look
ambiguous, under certain circumstances, the couple of typeOf overloads
can become ambiguous. Concretely, ambiguity happens when T <: TypeTag[T],
which makes the compiler uncapable to choose an overload to typecheck
`typeOf[T](<materialized>: TypeTag[T])`. Luckily, defining x as a by-name
parameter fixes the problem.
def typeOf[T](implicit ttag: TypeTag[T]): Type
def typeOf[T: TypeTag](x: => T): Type
The second problem manifested itself in reification of snippets that
contained calls to typeOf. Apparently, materialized tags get rolled back
by reify as products of macro expansion, becoming replaced with
`implicitly[TypeTag[T]]`. Afterwards, subsequent rollback of TypeTree's
strips the replacement of its type argument, producing bare `implicitly`.
Back then when typeOf wasn't overloaded, this abomination typechecked
and worked correctly, but now, due to some weird reason, it stopped.
I have worked around this by performing the rollback on a larger scale -
instead of hunting down materialized tags, this commit detects calls
to typeOf and removes their implicit argument lists altogether.
Diffstat (limited to 'test/files/run/reify_typeof.check')
-rw-r--r-- | test/files/run/reify_typeof.check | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/test/files/run/reify_typeof.check b/test/files/run/reify_typeof.check new file mode 100644 index 0000000000..670f76faa4 --- /dev/null +++ b/test/files/run/reify_typeof.check @@ -0,0 +1,10 @@ +Expr[Unit]({ + val ru = `package`.universe; + val tpe1: ru.Type = ru.typeOf[`package`.List[Int]]; + Predef.println(tpe1); + val tpe2: ru.Type = ru.typeOf(List.apply(1, 2, 3)); + Predef.println(tpe2) +}) +scala.List[Int] +List[Int] +() |