AndreVanDelft / scala

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

Parser does not recognize local var&val initializer #61

Open AndreVanDelft opened 9 years ago

AndreVanDelft commented 9 years ago

Regression:

def test = {
      val i = -4
      {println(i)}
  }

yields

error: Int(-4) does not take parameters
      {println(i)}
      ^

It appears that scanner correctly inserts a NEWLINE after the -4, but method simpleExpr() of the Parser parses this number and then continues with simpleExprRest(t, canApply = true); the latter starts with

if (canApply) newLineOptWhenFollowedBy(LBRACE)

It seems that the regular Scala compiler (2.11) has the same code; in a worksheet in Eclipse it gives the same problem. Scala 2.8 online REPL, seems to behave better.

So it seems SubScript is well compatible with the current Scala version. But do we want that?

AndreVanDelft commented 9 years ago

The SLS states, among others:

ArgumentExprs ::= ‘(’ [Exprs] ‘)’
               | ‘(’ [Exprs ‘,’] PostfixExpr ‘:’ ‘_’ ‘*’ ’)’
               | [nl] BlockExpr

So a new line is optional for a BlockExpr; and this just happens not to be applicable to a number. So scalac has it quite right. However, for SubScript the opening brace should just introduce a code fragment, so we should change the behaviour a little.