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
Invalid escape sequences in s"" interpolated strings throw at runtime, inconsistent with f"" and double quoted strings #9234
Comments
Imported From: https://issues.scala-lang.org/browse/SI-9234?orig=1 |
Gary Hewett (techano) said: play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[InvalidEscapeException: invalid escape '\s' not one of [\b, \t, \n, \f, \r, \, ", '] at index 2 in "),\s+(". Use \ for literal .]] I'd cast my vote (if possible) that yes a compile time error on this would definitely trump runtime errors... |
Hubert Czerpak (hczerpak) said: |
@som-snytt said (edited on Feb 2, 2017 12:23:34 AM UTC): Just wanted to say, once more, how I don't like spending time formatting JIRA comments. I meant s"hello, ${"world"}" where the whole. string is a literal. Wow, it also borked that. No, I refuse to click the question mark link to research the formatting language. I have a life, too. |
Hubert Czerpak (hczerpak) said: |
Just got hit by this, would love to see a fix. |
It looks like this may be fixed in 2.13 (see scala/scala-dev#475), but can't be in 2.12 for bincompat reasons |
There is a trivial test test/files/neg/t6631.scala
|
Compiling
produces a compile-time error like:
The standard s"" and f"" string interpolators use the same escape sequences as normal double quoted strings. Like double quoted strings the f"" interpolator reports bad sequences at compile time.
Inconsistently, the s"" string interpolator reports bad escape sequences at runtime by throwing an exception.
For example, compiling the following code succeeds:
At run time invoking f will produce an exception:
I would prefer that the s"" interpolator report bad escape errors as early as possible, consistent with standard double quoted strings and f"" interpolated strings.
The text was updated successfully, but these errors were encountered: