AndreVanDelft / scala

The SubScript extension to the Scala programming language
http://www.subscript-lang.org/
12 stars 1 forks source link

Compiler throws an exception on attempt to create a new object with "new" in script variable definition #51

Closed anatoliykmetyuk closed 9 years ago

anatoliykmetyuk commented 9 years ago

Consider the following script:

  def script live = (
    val i: String = new String("Hello")
    {println(i)}
  )

On compilation, the compiler will fail with the following exception:

[ant:scalac] java.lang.OutOfMemoryError: Java heap space
[ant:scalac]    at java.lang.Integer.valueOf(Integer.java:625)
[ant:scalac]    at scala.runtime.BoxesRunTime.boxToInteger(BoxesRunTime.java:69)
[ant:scalac]    at scala.tools.nsc.ast.parser.Parsers$UnitParser.syntaxError(Parsers.scala:233)
[ant:scalac]    at scala.tools.nsc.ast.parser.Parsers$Parser.simpleScriptTerm(Parsers.scala:2600)
...

In general, it seems that every script variable/value declaration that involves the new keyword on its right-hand side will cause such an exception.

A workaround is to enclose the right-hand side in the parentheses:

  def script live = (
    val i: String = (new String("Hello"))
    {println(i)}
  )
AndreVanDelft commented 9 years ago

Probably this will be solved when we opt for [this treatment of var/val declarations](a minute ago).

AndreVanDelft commented 9 years ago

Solved indeed.