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
Interpolation and multi-line string literals mis-interact #7554
Comments
Imported From: https://issues.scala-lang.org/browse/SI-7554?orig=1 |
Sarah Gerweck (gerweck) said: |
@paulp said: |
@paulp said: The triple vs single quoted issue is an example of string interpolation being broken by design, but it's not a spec violation. String interpolation happens after the literal, and it's the interpolator which is processing the backslash. |
Sarah Gerweck (gerweck) said: The language spec says about triple-quoted strings: "None of the escape sequences in (§1.3.6) is interpreted." Are you suggesting that putting an The whole point of triple-quoted strings is to disable all the quoting rules and let you paste in strings verbatim. I also don't see why it would be desirable to require escaping only in the case of an interpolated string, even if the language spec didn't state clearly that you don't need escaping in a triple-quoted string. |
@paulp said: And it isn't "desirable" that it's this way, that's why I said it is an example of their being broken by design. If it assists in deciphering intent, every word you are parsing in the language spec was written before string interpolation was even a notion. Anything which sounds like it refers to string interpolation is coincidental. The spec has been abandoned so you have to apply some filters when trying to make sense of it. It reasonably adequately summarizes the language of 2006, seven years ago. |
@SethTisue said: |
The Scala language spec §1.3.5 indicates that multi-line string literals are not subject to interpolation. For example, you might write a regular expression as
"""test-config\.xml"""
to match a particular string. Unlike in regular strings, the backslash before the period is not escaped.However, the compiler does not behave correctly when these multi-line literals are used in conjunction with string interpolation. E.g.:
This should produce the same pattern mentioned above. Instead, it produces a runtime error about an invalid string. You can work around this by double-escaping any backslashes, but this is not consistent with the language specification.
The text was updated successfully, but these errors were encountered: