Re: Toolbox typecheck throws MatchError for higher-kinded path-dependent type
Simon Schäfer <[email protected]>
| Newsgroups | gmane.comp.lang.scala |
|---|---|
| Message-ID | <[email protected]> |
It is known that the ToolBox is full of bugs. I wouldn't bother with it
at all - use a regular instance of Global instead.
Example:
import scala.reflect.internal.util.AbstractFileClassLoader
import scala.tools.nsc.Settings
import scala.reflect.io.PlainDirectory
import scala.reflect.io.VirtualDirectory
import scala.tools.nsc.settings.ScalaVersion
import scala.reflect.internal.util.BatchSourceFile
import scala.tools.nsc.interactive.Global
import scala.tools.nsc.reporters.StoreReporter
import scala.tools.nsc.interactive.Response
object CompilerTest extends App {
val dir = new VirtualDirectory("<virtualdir>", None)
// Gives access to all generated class files.
val classLoader = new AbstractFileClassLoader(dir,
getClass.getClassLoader)
val s = new Settings(err ⇒ Console.err.println(err))
s.outputDirs.setSingleOutput(dir)
s.usejavacp.value = true
s.source.value = ScalaVersion("2.11.7")
// specify dependencies here
s.bootclasspath.value = ""
s.classpath.value = ""
val reporter = new StoreReporter
val compiler = new Global(s, reporter)
val run = new compiler.Run
val src = s"""
class Test {
val x = {
0
}
val y = { x+1 }
}
"""
val srcFile = new BatchSourceFile("<memory>", src)
val resp = new Response[compiler.Tree]
compiler.askLoadedTyped(srcFile, resp)
val tree = resp.get.left.get
import compiler._
...
}
On 28.07.2015 22:54, Daniel Armak wrote:
>
> Hi,
>
> I encountered this error trying to compile code that uses the
> shapeless ~?> typeclass with the toolbox, and simplified it to this:
>
> |
> import scala.reflect.runtime.currentMirror
> import scala.tools.reflect.ToolBox
>
> val tb = ToolBox(currentMirror).mkToolBox()
> val source = """{
> import scala.language.higherKinds
>
> class Outer[X] {
> class Inner[Y]
> }
> class Other[T[_]]
>
> new Other[Outer[Int]#Inner]()
> }"""
>
> val tree = tb.parse(source)
> tb.typecheck(tree).tpe
> |
>
> This fails with:
>
> |Exception in thread "main" scala.MatchError: <tree with deferred refcheck> (of class scala.tools.nsc.ast.Trees$TypeTreeWithDeferredRefCheck)
> at scala.reflect.internal.Importers$StandardImporter.recreateTree(Importers.scala:309)
> |
>
> (Full stack trace here
> <https://gist.github.com/danarmak/c917b4f35e5d4d6ccbc7>)
>
> I’m using scala 2.11.7.
>
> Thanks,
>
> Daniel Armak
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-language" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups "scala-language" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.