question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Incorrect handle of unicode escapes in triple-quoted string

See original GitHub issue

Compiler version

3.0.0-RC1

Minimized code

object Bar{
  def main(args: Array[String]): Unit = {
    println(""""\\\uCAFE"""".getBytes.toList)
  }
}

Output

This is what it prints in 3.0.0-RC1

List(34, 92, 92, 92, 117, 67, 65, 70, 69, 34)

Expectation

This is what it prints in 2.13.4 and 2.12.13

List(34, 92, 92, -20, -85, -66, 34)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
lrytzcommented, Mar 8, 2021

raw""""\\${'\uCAFE'}"""" also works

1reaction
martijnhoekstracommented, Mar 7, 2021

2.13 emits a deprecation warning for the escape in a triple quoted string, scala 3 doesn’t handle the escape anymore. I believe that behaviour follows the principle of least astonishment: Unicode escapes are treated as any other escape, that is to say, they’re escaped in single quoted strings, backquoted identifiers and char literals and by the f and s interpolators.

The three options that will work with any version are

  • Use a literal (which is usually the best idea)
  • Use a a raw interpolation and interpolate it in, which can be useful for non-printable characters
  • Use an interpolation or single-quoted string and escape the other things too, when the unicode escape is the only thing you need to escape (i.e. not here)

For this particular string, those are respectively """"\\쫾"""", raw"$"\\${'\uCAFE'}$"" and "\"\\\\\uCAFE\""

Reference https://github.com/lampepfl/dotty/pull/8480 and https://github.com/scala/scala/pull/8282

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unicode escapes in triple quoted strings are deprecated, use ...
Unicode escapes in triple quoted strings are deprecated, use the literal character instead : r/scala.
Read more >
(unicode error)" occur when raw string is in triple quotes ...
I have tried moving the triple quotes to align with various parts of the code but nothing has worked so far. Because \N...
Read more >
ASCII and Unicode quotation marks
If you can use Unicode characters, nice directional quotation marks are available in the form of characters U+2018, U+2019, U+201C, and U+201D (as...
Read more >
How to Handle the Unclosed String Literal Error in Java - Rollbar
Python unclosed string literal error refers to the Java compiler failing to interpret a string literal due to the missing of a double...
Read more >
Python Strings | Python Education - Google Developers
Backslash escapes work the usual way within both single and double quoted literals -- e.g. \n \' \". A double quoted string literal...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found