The semicolon inference doesn't work when an assignment statement is followed by curly braces in Scala? -


@ http://www.artima.com/pins1ed/builtin-control-structures.html#7.7 , see following code

val = 1; {   val = 2   println(a) } println(a) 

where says semicolon required here, why?

from rule @ http://www.artima.com/pins1ed/classes-and-objects.html#4.2 , think semicolon should auto added since

  1. val = 1 can legal statement.
  2. the next line begins {, think can start legal statement. (since there's no compile error if add semicolon , separate first 2 lines 2 statements.)
  3. val = 1 not in parentheses or brackets.

because legal call apply:

implicit class richint(i: int) {   def apply(thunk: => unit) = 33 }  val = 1 {   val = 2   println(a) } println(a)  // 33 ! 

1 { ... } short 1.apply {...}. apply not defined int default, implicit enrichment shows, possible.


edit: semicolon inference conditions described in 'ยง1.2 newline characters' of scala language specification. inferred semicolon called 'special token "nl"' in text.

in general, 3 rules given (summarised ex-negativo in blog entry), , in example satisfied. reason semicolon still not inferred given further down in text.

the scala grammar ... contains productions optional nl tokens, not semicolons, accepted. has effect newline in 1 of these positions not [!] terminate expression or statement.

the relevant case of such rule following:

a single new line token accepted
โ€“ in front of opening brace โ€œ{โ€, if brace legal continuation of current statement or expression ...

example 1.2.2 shows case of anonymous subclass had referred in comment.


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -