I was trying to follow an example from another question, and I came upon something I cannot explain:
scala> import scala.reflect.runtime.{currentMirror => m}
import scala.reflect.runtime.{currentMirror=>m}
scala> m.mkToolBox()
<console>:12: error: value mkToolBox is not a member of reflect.runtime.universe.Mirror
m.mkToolBox()
^
scala> import scala.tools.reflect.ToolBox
import scala.tools.reflect.ToolBox
scala> m.mkToolBox()
res3: scala.tools.reflect.ToolBox[reflect.runtime.universe.type] = scala.tools.reflect.ToolBoxFactory$ToolBoxImpl@225765b0
How come mkToolBox
is not a member of m
before importing ToolBox
, but is afterwards?
ToolBox
is an implicit class that pimpsmkToolBox
ontoMirror
. Same story withEval
, which pimpseval
.If I examine it with
reify
, I see this:That means there's a method call to a function named
ToolBox
inside the package objectscala.tools.reflect
. It is not an object, becausereify
would expose theapply
method.So, even though the API Docs for the Compiler do not show anything but the trait on the left side, if you look at the package you'll see an implicit method definition.
PS: Yes, this was a real question. The thought of an uppercase-starting method with the same name of a trait did not occur to me, until I thought of reifying the thing to get the tree.