Skip to content

Toolbox.parse chokes on package declaration #6657

@scabug

Description

@scabug

This REPL session show the problem:

import scala.reflect.runtime.{currentMirror => cm}
import scala.tools.reflect.ToolBox
val toolbox = cm.mkToolBox()
toolbox.parse("package Foo; class Bar")

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

illegal start of definition
	at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.throwIfErrors(ToolBoxFactory.scala:318)
	at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl$ToolBoxGlobal.parse(ToolBoxFactory.scala:289)
	at scala.tools.reflect.ToolBoxFactory$ToolBoxImpl.parse(ToolBoxFactory.scala:405)

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?

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions