New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow \" in single-quoted interpolated string literals #11751
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this one was wrongly interpreted as \"
instead of "
. The check file differs with the one in Scala 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I filed #11750 about that
println(f"\"Hello\", $person") | ||
println(f"""\"Hello\", $person""") | ||
|
||
println(raw"\"Hello\", $person") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 araw
now?
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 instead
If 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