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.parse chokes on package declaration #6657
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6657?orig=1 |
@xeno-by said: |
@xeno-by said: |
@gkossakowski said: This is not a blocker for me. I just noticed this problem while playing with reflection. |
John Eckhart (jeckhart) said: |
@densh said: |
@densh said: |
Johann Egger (lapislazuli) said: import scala.reflect.runtime.universe._
import scala.tools.reflect.ToolBox
val input = """package foo.bar
class Test {
}"""
val toolbox = runtimeMirror(getClass.getClassLoader).mkToolBox()
toolbox.parse(input) results in scala.tools.reflect.ToolBoxError: reflective compilation has failed:
'{' expected but ';' found.
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.throwIfErrors(ToolBoxFactory.scala:315)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.parse(ToolBoxFactory.scala:290)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$parse$1.apply(ToolBoxFactory.scala:416)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$$anonfun$parse$1.apply(ToolBoxFactory.scala:413)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.liftedTree2$1(ToolBoxFactory.scala:354)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$withCompilerApi$.apply(ToolBoxFactory.scala:354)
at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.parse(ToolBoxFactory.scala:413)
... 46 elided my current workaround is surrounding package declarations with curly-brackets. val input = """
package foo.bar{
class Test {
}
}""" this results in a valid tree. However calling java.lang.AssertionError: assertion failed: value <local <expression-owner>>
at scala.reflect.internal.Symbols$Symbol.newPackage(Symbols.scala:309)
at scala.tools.nsc.typechecker.Namers$Namer.createPackageSymbol(Namers.scala:380)
at scala.tools.nsc.typechecker.Namers$Namer.createPackageSymbol(Namers.scala:373)
... |
@retronym said: cat sandbox/test.scala
import scala.reflect.runtime.universe._
import scala.tools.reflect.ToolBox
object Test extends App {
val input = """package foo.bar {
class Test {
}}"""
val toolbox = runtimeMirror(getClass.getClassLoader).mkToolBox()
toolbox.parse(input)
} The syntax you use is only applicable to entire compilation units, and not to fragments parsed by toolboxes. @densh If you believe it is feasible to add support top level package clauses, please open a new ticket with Johann's test case. |
@densh said: |
Julian Peeters (julianpeeters) said (edited on May 21, 2016 7:27:51 PM UTC): """package example
|
|case class Person(vehicle: test.major.Vehicle)
|
|package test.major
|
|case class Vehicle(name: String)""".stripMargin Let me know if you'd like me to file a new issue. |
Julian Peeters (julianpeeters) said: |
This REPL session show the problem:
Quick glance over the code:
https://github.com/scala/scala/blob/2.10.x/src/compiler/scala/tools/reflect/ToolBoxFactory.scala#L283
makes it clear why it fails. This should be fixed either by changing wrapper to being a package instead of object or documenting it clearly. I think the former option is a winner.
Eugene, can you comment?
The text was updated successfully, but these errors were encountered: