Why does an empty string with the string interpolation prefix fail to compile when followed by a statement?
For example
val test = s""
println("hello")
Fails to compile with error
error: value println is not a member of String
possible cause: maybe a semicolon is missing before `value println'?
println("hello")
But the following all compile fine:
val test = s""
val test = ""
println("hello")
def test() { s"" }
println("hello")
val test = s" "
println("hello")
It's a parser bug, fixed last January, so this should be ok in the latest 2.11.x releases.
Here's the bug report: https://issues.scala-lang.org/browse/SI-7919. The relevant comment (by Paul Phillips) is:
It's losing the newline token after a completely empty interpolated string. If it's
s"1"
, or a semicolon instead of a newline, or two newlines, or a comment after the empty string, it compiles.class A { s"" 5 }
Here's the PR that fixed it: https://github.com/scala/scala/pull/3411
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With