Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala string interpolation with escaped quote fails

Tags:

scala

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 string interpolation, it fails:

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

Even after we provide closing escaped quote.

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

Why does this happen?

like image 367
tuxdna Avatar asked Dec 06 '15 20:12

tuxdna


1 Answers

This appears to be a known bug.

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

scala> val a = s"""""""" // seven quote characters all up!
a: String = "
like image 79
Shadowlands Avatar answered Sep 18 '22 01:09

Shadowlands