Scala string interpolation with escaped quote not performed

scala> util.Properties.versionString
res11: String = version 2.11.2

scala> val a = ""
a: String = ""

scala> val a = "\""
a: String = "

So far so good. Now with the interpolation string, it fails:

scala> val a = s"\""
<console>:1: error: unclosed string literal
       val a = s"\""
                   ^

Even after we provide a closed escaped quote.

scala> val a = s"\"\""
<console>:7: error: value \ is not a member of String
       val a = s"\"\""
                   ^

Why is this happening?

+4
source share
1 answer

This is apparently a known mistake .

Note that you can get around this, at least for your case above, using triple quotes:

scala> val a = s"""""""" // seven quote characters all up!
a: String = "
+10
source

Source: https://habr.com/ru/post/1618815/


All Articles