Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
scabug opened this issue Jul 28, 2015 · 4 comments
Milestone

Comments

@scabug
Copy link

scabug commented Jul 28, 2015

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
Copy link
Author

scabug commented Jul 28, 2015

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

@scabug
Copy link
Author

scabug commented Jul 28, 2015

@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
Copy link
Author

scabug commented Jul 31, 2015

@paulp said:
See also #7243.

@scabug
Copy link
Author

scabug commented Sep 10, 2015

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants