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)
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 scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Thanks for the report.
The bug is in Importer
s, which copies a tree from one compiler universe into another.
I notice that @mandubian also ran into the same problem.
It fails to account for a special tree, TypeTreeWithDeferredWithRefCheck
that exists between the typer and refchecks compiler phases, and is used when typechecking higher kinded type applications.
I’ve lodged your report as SI-9421.
Fixing it would require adding a default case in src/reflect/scala/reflect/internal/Importers.scala
importTree
that forwarded to an extension hook that could be implemented in nsc.Global
. This pattern is already used in TreePrinters
, see in particular xprinttree
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.
--
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 scala-languag...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Why, is there anything wrong with the presentation compiler? Thanks!Hello,
This example produces an untyped tree (run.units.toList.head.body.tpe
is NoType).
Is there a way to use Global to produce typed trees? Otherwise I won’t be able to do effective typechecking when compiling values whose type is subject to erasure.
--
This example produces an untyped tree (
run.units.toList.head.body.tpe
is NoType).
An untyped tree has a null type, NoType
is the result of typechecking things like PackageDef
/ ClassDef
/ DefDef
trees.
I’ve updated the gist to include the output of show(tree, printTypes = true)
that shows the types you’ll find deeper in the tree.
-jason
--
Very roughly, how does treatment of code snippets compare among Toolbox, IMain and the standard REPL (aka Scala Shell)? Thanks!Hello,
In the ToolBox, snippets are wrapped in something like:
package wrapper$N { object O { def m: Any = {
<your code here>
}}
The REPL (aka IMain) has a more elaborate scheme to allow you to refer to symbols defined on previous lines.