title: Getting type information inside scala repl via IMain
body: <h2>Intent</h2>
  
  <p>I am <a href="https://groups.google.com/forum/?fromgroups=#!topic/scala-internals/DdSg-qxOvyo" rel="noreferrer">trying to add</a> support for <code>:kind</code> command to <a href="/questions/tagged/scala" class="post-tag" title="show questions tagged 'scala'" rel="tag">scala</a> repl. Thanks to Eugene Burmako, I was able to get a <a href="https://gist.github.com/folone/5261743" rel="noreferrer">working prototype</a>. Though it only works with fully qualified names and fails to resolve imported names.</p>
  
  <p>I am now trying to use <a href="http://www.scala-lang.org/archives/downloads/distrib/files/nightly/docs/compiler/index.html#scala.tools.nsc.interpreter.IMain" rel="noreferrer"><code>IMain.exprTyper</code></a> to do the job, as it is aware of types, imported into the repl. But there is a problem. Everything I've tried returns a <a href="http://www.scala-lang.org/api/current/index.html#scala.reflect.api.Types%24ClassInfoType" rel="noreferrer"><code>ClassInfoType</code></a> like the following (displayed with <a href="http://www.scala-lang.org/api/current/index.html#scala.reflect.api.Printers" rel="noreferrer"><code>showRaw</code></a>):</p>
  
  <pre><code>ClassInfoType(List(TypeRef(TypeRef(TypeRef(TypeRef(NoPrefix(), package &lt;root&gt;, List()), package java, List()), package lang, List()), class Object, List()), TypeRef(TypeRef(TypeRef(NoPrefix(), package &lt;root&gt;, List()), package scala, List()), trait Serializable, List())), Scope{
    def &lt;init&gt;(): Option.type;
    implicit def option2Iterable(xo: Option): Iterable;
    def apply(x: Object): Option;
    def empty(): Option;
    private def readResolve(): Object
  }, object Option)
  </code></pre>
  
  <p>While the working implementation returns specific <code>Type</code>:</p>
  
  <pre><code>PolyType(List(TypeName("A")), ClassInfoType(List(TypeRef(ThisType(scala), TypeName("AnyRef"), List()), TypeRef(ThisType(scala), scala.Product, List()), TypeRef(ThisType(scala), scala.Serializable, List())), Scope(nme.CONSTRUCTOR, TermName("isEmpty"), TermName("isDefined"), TermName("get"), TermName("getOrElse"), TermName("orNull"), TermName("map"), TermName("fold"), TermName("flatMap"), TermName("flatten"), TermName("filter"), TermName("filterNot"), TermName("nonEmpty"), TermName("withFilter"), TypeName("WithFilter"), TermName("contains"), TermName("exists"), TermName("forall"), TermName("foreach"), TermName("collect"), TermName("orElse"), TermName("iterator"), TermName("toList"), TermName("toRight"), TermName("toLeft")), scala.Option))
  </code></pre>
  
  <h2>Question</h2>
  
  <p>I feel like I'm really close. Here's a playground, you can use to try everything yourself:</p>
  
  <pre><code>Welcome to Scala version 2.11.0-20130328-093148-47645c7e7e (OpenJDK 64-Bit Server VM, Java 1.7.0_17).
  Type in expressions to have them evaluated.
  Type :help for more information.
  
  scala&gt; import scala.reflect.runtime.universe._
  import scala.reflect.runtime.universe._
  
  scala&gt; import scala.tools.nsc.interpreter.IMain
  import scala.tools.nsc.interpreter.IMain
  
  scala&gt; val mirror = runtimeMirror(getClass.getClassLoader) // Working approach
  mirror: reflect.runtime.universe.Mirror = JavaMirror with scala.tools.nsc.interpreter.IMain$TranslatingClassLoader@3d34ec98 of type class scala.tools.nsc.interpreter.IMain$TranslatingClassLoader with classpath [&lt;unknown&gt;] and parent being scala.tools.nsc.util.ScalaClassLoader$URLClassLoader@5d990e8c of type class scala.tools.nsc.util.ScalaClassLoader$URLClassLoader with classpath [file:/usr/lib/jvm/java-7-openjdk/jre/lib/resources.jar,file:/usr/lib/jvm/java-7-openjdk/jre/lib/rt.jar,file:/usr/lib/jvm/java-7-openjdk/jre/lib/jsse.jar,file:/usr/lib/jvm/java-7-openjdk/jre/lib/jce.jar,file:/usr/lib/jvm/java-7-openjdk/jre/lib/charsets.jar,file:/usr/lib/jvm/java-7-openjdk/jre/lib/rhino.jar,file:/home/folone/workspace/scala-myfork/build/pack/lib/jline.jar,file:/home/folone/workspace/scala-myfork...
  
  scala&gt; val typer = new IMain().exprTyper // Not working approach
  typer: scala.tools.nsc.interpreter.IMain#exprTyper.type = scala.tools.nsc.interpreter.IMain$exprTyper$@68c181f0
  
  scala&gt; val expr = "scala.Option"
  expr: String = scala.Option
  
  scala&gt; showRaw(mirror.staticClass(expr).toType.typeSymbol.typeSignature) // Correct signature
  res6: String = PolyType(List(TypeName("A")), ClassInfoType(List(TypeRef(ThisType(scala), TypeName("AnyRef"), List()), TypeRef(ThisType(scala), scala.Product, List()), TypeRef(ThisType(scala), scala.Serializable, List())), Scope(nme.CONSTRUCTOR, TermName("isEmpty"), TermName("isDefined"), TermName("get"), TermName("getOrElse"), TermName("orNull"), TermName("map"), TermName("fold"), TermName("flatMap"), TermName("flatten"), TermName("filter"), TermName("filterNot"), TermName("nonEmpty"), TermName("withFilter"), TypeName("WithFilter"), TermName("contains"), TermName("exists"), TermName("forall"), TermName("foreach"), TermName("collect"), TermName("orElse"), TermName("iterator"), TermName("toList"), TermName("toRight"), TermName("toLeft")), scala.Option))
  
  scala&gt; showRaw(typer.typeOfExpression(expr).typeSymbol.typeSignature) // Wrong signature
  res7: String = 
  ClassInfoType(List(TypeRef(TypeRef(TypeRef(TypeRef(NoPrefix(), package &lt;root&gt;, List()), package java, List()), package lang, List()), class Object, List()), TypeRef(TypeRef(TypeRef(NoPrefix(), package &lt;root&gt;, List()), package scala, List()), trait Serializable, List())), Scope{
    def &lt;init&gt;(): Option.type;
    implicit def option2Iterable(xo: Option): Iterable;
    def apply(x: Object): Option;
    def empty(): Option;
    private def readResolve(): Object
  }, object Option)
  </code></pre>
  
  <p>How do I transform <code>ClassInfoType</code> into a valid <code>Type</code> containing the needed info? Alternatively, how do I get the <code>Type</code> using <code>IMain</code> in the first place?</p>