scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

ToolBox compiler fails with higher kinded types due because Importers doesn't deal with TypeTreeWithDeferredRefCheck #9421

Open scabug opened 9 years ago

scabug commented 9 years ago

As reported by Daniel Armak on the mailing list:

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)

Importers doesn't deal with the extra AST node types introduced in nsc.Global, namely TypeTreeWithDeferredRefCheck

scabug commented 9 years ago

Imported From: https://issues.scala-lang.org/browse/SI-9421?orig=1 Reporter: @retronym Affected Versions: 2.11.7 See #7243, #8777

scabug commented 9 years ago

@retronym said (edited on Jul 28, 2015 11:39:43 PM UTC): Fixing it would require adding a default case in src/reflect/scala/reflect/internal/Importers.scala importTree that forwards to an extension hook that could be implemented in nsc.Global. This pattern is already used in TreePrinters, see in particular xprinttree

scabug commented 9 years ago

@paulp said: See also #7243.

scabug commented 9 years ago

@retronym said (edited on Sep 10, 2015 1:36:09 PM UTC): I've started to add the extension point to Importers in the last commit here: https://github.com/scala/scala/compare/scala:2.11.x...retronym:topic/ximporter-annotation-completion?expand=1

It wasn't working as I had hoped, I suspect there is an underlying bug in the compiler generating the right bridge methods down the cake for the method I added.

Reminds me a little of aspects of #8777.