Scala Programming Language
  1. Scala Programming Language
  2. SI-6657

Toolbox.parse chokes on package declaration

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-RC2
    • Fix Version/s: Scala 2.11.0-M7
    • Component/s: Macros
    • Labels:
      None

      Description

      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?

        Activity

        Hide
        Eugene Burmako added a comment -

        I implemented this to be consistent with tb.typeCheck and tb.eval, which also choke on packages. I'll ask Martin why it was done like this in the first place.

        Show
        Eugene Burmako added a comment - I implemented this to be consistent with tb.typeCheck and tb.eval, which also choke on packages. I'll ask Martin why it was done like this in the first place.
        Hide
        Eugene Burmako added a comment -

        Is this a blocker for any of your scenarios btw?

        Show
        Eugene Burmako added a comment - Is this a blocker for any of your scenarios btw?
        Hide
        Grzegorz Kossakowski added a comment -

        Thanks for response. Actually, I think you need several methods. parse should be a method that does not do any wrapping and then parseDe for parsing src in definition position (as parse does at the moment) and then parseExpr to parse expressions.

        This is not a blocker for me. I just noticed this problem while playing with reflection.

        Show
        Grzegorz Kossakowski added a comment - Thanks for response. Actually, I think you need several methods. parse should be a method that does not do any wrapping and then parseDe for parsing src in definition position (as parse does at the moment) and then parseExpr to parse expressions. This is not a blocker for me. I just noticed this problem while playing with reflection.
        Hide
        John Eckhart added a comment -

        I encountered this when trying to update the Sonar Scala plugin to use the reflective parser. Is the only workaround to use the tools.nsc compiler api?

        Show
        John Eckhart added a comment - I encountered this when trying to update the Sonar Scala plugin to use the reflective parser. Is the only workaround to use the tools.nsc compiler api?
        Hide
        Jason Zaugg added a comment -

        @Denys / @Eugene: Should we add parseTopLevel? I sort of thought I'd seen this already but I can't find it now.

        Show
        Jason Zaugg added a comment - @Denys / @Eugene: Should we add parseTopLevel ? I sort of thought I'd seen this already but I can't find it now.
        Hide
        Denys Shabalin added a comment -

        Adding another entry point is quick and simple way to fix the problem but I still have the hope that we can get away with just one. We can probably customize rules for parseStats to take packages into account but I've not really looked at it yet. There is a symmetrical quasiquotes issue SI-6841.

        Show
        Denys Shabalin added a comment - Adding another entry point is quick and simple way to fix the problem but I still have the hope that we can get away with just one. We can probably customize rules for parseStats to take packages into account but I've not really looked at it yet. There is a symmetrical quasiquotes issue SI-6841 .
        Hide
        Denys Shabalin added a comment -
        Show
        Denys Shabalin added a comment - Fixed in https://github.com/scala/scala/pull/3007

          People

          • Assignee:
            Denys Shabalin
            Reporter:
            Grzegorz Kossakowski
          • Votes:
            1 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development