4

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")

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.