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

showCode does not produce executable code #9854

Open
scabug opened this issue Jul 11, 2016 · 3 comments
Open

showCode does not produce executable code #9854

scabug opened this issue Jul 11, 2016 · 3 comments
Milestone

Comments

@scabug
Copy link

scabug commented Jul 11, 2016

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_77).
Type in expressions for evaluation. Or try :help.

scala> :paste
// Entering paste mode (ctrl-D to finish)

import scala.tools.reflect.ToolBox
import scala.reflect.runtime.universe._
val code = showCode(reify {
  import scala.collection.immutable._
  HashMap(1 -> "x")
}.tree) 
val tb = runtimeMirror(getClass.getClassLoader).mkToolBox()
tb.eval(tb.parse(code))

// Exiting paste mode, now interpreting.

scala.tools.reflect.ToolBoxError: reflective compilation has failed:

object apply is not a member of package HashMap
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.throwIfErrors(ToolBoxFactory.scala:316)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.wrapInPackageAndCompile(ToolBoxFactory.scala:198)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.compile(ToolBoxFactory.scala:252)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$compile$2.apply(ToolBoxFactory.scala:429)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$compile$2.apply(ToolBoxFactory.scala:422)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.liftedTree2$1(ToolBoxFactory.scala:355)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.apply(ToolBoxFactory.scala:355)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.compile(ToolBoxFactory.scala:422)
  at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.eval(ToolBoxFactory.scala:444)
  ... 37 elided

I expect the code generated by showCode could be parsed and evaluated. Unfortunately it does not.

@scabug
Copy link
Author

scabug commented Jul 11, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9854?orig=1
Reporter: @Atry
Affected Versions: 2.11.8

@scabug
Copy link
Author

scabug commented Jul 12, 2016

@som-snytt said:
FWIW,

scala> val code = showCode(q"""import scala.collection.immutable._ ; HashMap(1 -> "x")""")
code: String =
{
  import scala.collection.immutable._;
  HashMap((1).->("x"))
}

scala> val tb = runtimeMirror(getClass.getClassLoader).mkToolBox()
tb: scala.tools.reflect.ToolBox[reflect.runtime.universe.type] = scala.tools.reflect.ToolBoxFactory$ToolBoxImpl@270a73ba

scala> tb.eval(tb.parse(code))
res1: Any = Map(1 -> x)

scala> val code = showCode(reify {
     |   import scala.collection.immutable._
     |   HashMap(1 -> "x")
     | }.tree) 
code: String =
{
  import immutable._;
  HashMap.apply(Predef.ArrowAssoc(1).->("x"))
}

@scabug
Copy link
Author

scabug commented Aug 3, 2016

@SethTisue said:
I wouldn't get your hopes up for a fix (except in the context of http://scalameta.org)

@scabug scabug added this to the Backlog milestone Apr 7, 2017
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

2 participants