Allow \" in single-quoted interpolated string literals#11751
Allow \" in single-quoted interpolated string literals#11751nicolasstucki merged 1 commit intoscala:masterfrom
Conversation
`\"` no longer closes single-quoted interpolated string literals. The escape sequence is not processed by the scanner.
| println(s"\"Hello\", $person") | ||
| println(s"""\"Hello\", $person""") | ||
|
|
||
| println(f"\"Hello\", $person") |
There was a problem hiding this comment.
It looks like this one was wrongly interpreted as \" instead of ". The check file differs with the one in Scala 2.
| println(f"\"Hello\", $person") | ||
| println(f"""\"Hello\", $person""") | ||
|
|
||
| println(raw"\"Hello\", $person") |
There was a problem hiding this comment.
Questions: Now that we have $" as way to escape " in any string interpolator, do we really need to special case \" in raw interpolators? Cant we just assume that raw"\" is "\"? How can we end with a \ in a raw now?
There was a problem hiding this comment.
do we really need to special case
\"in raw interpolators?
Maybe I misunderstand, but there's no special case or change in the raw interpolator. The change here is that \" no longer closes the string literal, but the interpretation of \" is unchanged (raw"""\"""" and s"""\"""" are the same as before).
In my opinion we should do this change change and fix scala/bug#6476, even if we have $" now. This issue affected a lot of people, and will keep affecting a lot of people in the future, especially beginners (https://stackoverflow.com/questions/21086263/how-to-insert-double-quotes-into-string-with-interpolation-in-scala).
See also the (updated) PR description of scala/scala#8830 (comment).
Cant we just assume that
raw"\"is"\"?
I'm not sure what you mean by that.
How can we end with a
\in arawnow?
Using triple-quote. The 2.13 compiler will even tell you that:
scala> raw"c:\"
^
error: unclosed string literal; note that `\"` no longer closes single-quoted interpolated string literals since 2.13.6, you can use a triple-quoted string insteadIf desired, I can include this message in Scala 3 as well.
\"no longer closes single-quoted interpolated string literals.The escape sequence is not processed by the scanner.
Forward-port of scala/scala#8830