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-double-quoted string interpolations #8830
Conversation
I think we need to actually know what the safety level is. Either it's absolutely safe, or there are unsafe cases that need to be precisely characterized in order to know whether we're comfortable with advancing this. |
This comment has been minimized.
This comment has been minimized.
9fdd374
to
3e100a5
Compare
Not sure if you reviewed https://github.com/scala/scala/pulls?q=is%3Apr+author%3Asom-snytt+6476+is%3Aclosed especially #4308 has a dreary tail. |
@som-snytt I did see some of the discussion that took place, and that's one of my motivation behind lawyering up on the legality within current statute. |
I cherry picked 195d369 from Som's 2015 PR. This handles last backslash, so it's better than my implementation. |
04c2c0e
to
cf817c6
Compare
all escapes should be treated in the same way, not just |
@SethTisue Let's define safety as non-existence of:
We can rule out first and last I think. Is there a source that we can write that would change the meaning?
However I can make up a program that would evaluate differently: println(raw"1\"); println(2); // \"") In Scala 2.13.1 this would print: scala> println(raw"1\"); println(2); // \"")
1\
2 With this patch: 1\"); println(2); // \" It would be very unlikely that you'd have a comment |
I also noticed that looking ahead for another quote doesn't handle comments; it's a pretty severe limitation, but only worth fixing if the PR has a chance. |
The other backslash escape sequences like |
@eed3si9n sorry i thought this was related to raw strings, nvm then |
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.
Some comments from reviewing.
Also, we should fix the REPL, as it behaves differently to real compilation: scala> raw"\\"
val res0: String = \
scala> raw"\"
val res1: String = ""
scala> "\""
|
|
You typed two blank lines. Starting a new command.
scala> "\\"
^
error: unclosed string literal |
Dale and me were trying to come up with a few more examples around this; so your point is that the change can only prevent code from compiling that didn't work before, or vice-versa, but not make compile and run code differently (except for the very corner case you highlight)? this no longer compiles
this now compiles
I personally have doubts about speccing the |
|
I agree with that in principle, and I think we should have the fix you did in Scala 3 also in Scala 2. However, I really think for user-friendlyness moving from |
A subtlety (perhaps you knew this already): this doesn't treat $ scala --scala-pr 8830 -e 'println(s"he said: \"hi\" to me")'
he said: "hi" to me
$ scala --scala-pr 8830 -e 'println(raw"he said: \"hi\" to me")'
he said: \"hi\" to me
$
$ scala3
Starting scala3 REPL...
scala> s"he said: $"hi$" to me"
val res0: String = he said: "hi" to me
scala> raw"he said: $"hi$" to me"
val res1: String = he said: "hi" to me |
If I remember correctly, I cherry picked the last- |
#4308 (comment) is still true. The old PR is still an easy rebase on 2.12:
People misplace quotes and braces all the time and experience brain failure until they figure it out. A close quote is the next unescaped quote, or the last escaped quote on the line. Many of the "what about this" examples don't pass the Odersky test of sane people don't code like that. |
d54deff
to
9967206
Compare
(t7020.scala is flaky currently, likely since #9522) |
Pushed some spec'ese words for this change. |
Changing `"Hello, \"World\""` to `s"Hello, \"$who\""` no longer breaks. Before this change, `\"` terminated single-quoted interpolated string literals, now the string remains open. The scanner doesn't interpret the escape sequence, string interpolators can do so (`s` and `f` do). Breaking changes: - `raw"c:\"` no longer compiles, it's now an unclosed string - `raw"c:\" // uh"` used to evaluate to `"""c:\"""`, now it's `"""c:\" // uh"""`
Also, unicode escapes are no longer interpreted in interpolated strings. Interpolators can still interpret them, but that's not in the spec.
Rebased and squashed, updated the PR description. This is now ready, but let's see what the Scala 3 people say over at scala/scala3#11751. |
That was merged. So shall we (f-i-nally!) merge this now? |
@som-snytt you'll have to stop saying "when string interpolators support escaped double quotes" and go back to saying "when hell freezes over" like before @eed3si9n thanks for not giving up on this :-) |
Never gonna give |
I was going to go with flying pigs. My favorite part re-reading the ticket is when SethTisue says this is impossible now and eed3si9n submits a PR. |
Can't wait to find out who plays me in the movie version. |
Changing
"Hello, \"World\""
tos"Hello, \"$who\""
no longer breaks.Before this change,
\"
terminated single-quoted interpolated stringliterals, now the string remains open. The scanner doesn't interpret
the escape sequence, string interpolators can do so (
s
andf
do).Breaking changes:
raw"c:\"
no longer compiles, it's now an unclosed stringraw"c:\" // uh"
used to evaluate to"""c:\"""
, now it's"""c:\" // uh"""
Fixes scala/bug#6476