Scala string interpolation empty string compilation error

Why can't an empty string with a string interpolation prefix compile if I follow the instructions?

for instance

val test = s""
println("hello")

Unable 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 everything compiles fine:


val test = s""

val test = ""
println("hello")

def test() { s"" }
println("hello")

val test = s" "
println("hello")

+4
source share
1 answer

This is a parser bug fixed in January last year, so this should be fine in recent versions 2.11.x.

Here's the error report: https://issues.scala-lang.org/browse/SI-7919 . Relevant Comment (Paul Phillips):

. s"1" newline , .

class A {
  s""
  5
}

PR, : https://github.com/scala/scala/pull/3411

+7