diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala b/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala index d21d4b85b5df..6a1d5d8b216c 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala @@ -439,6 +439,7 @@ object JavaScanners { } oct.asInstanceOf[Char] end octal + var skip = false def greatEscape: Char = nextChar() if '0' <= ch && ch <= '7' then octal @@ -455,11 +456,12 @@ object JavaScanners { case '\\' => '\\' case CR | LF if inTextBlock => if !scanOnly then nextChar() + skip = true 0 case _ => if !scanOnly then error("invalid escape character", charOffset - 1) ch - if x != 0 then nextChar() + if !skip then nextChar() x end greatEscape @@ -470,7 +472,7 @@ object JavaScanners { val res = ch nextChar() res - if c != 0 && !scanOnly then putChar(c) + if !skip && !scanOnly then putChar(c) end getlitch /** Read a triple-quote delimited text block, starting after the first three double quotes. diff --git a/tests/run/t12290.check b/tests/run/t12290.check index c6ce23a28ef2..f5367692b5f8 100644 --- a/tests/run/t12290.check +++ b/tests/run/t12290.check @@ -64,3 +64,11 @@ XY ==== X Y ==== +582059 +==== +00 +==== +2a +==== +c3bf +==== diff --git a/tests/run/t12290/Test.scala b/tests/run/t12290/Test.scala index e6c96573f032..7b0133e61c1f 100644 --- a/tests/run/t12290/Test.scala +++ b/tests/run/t12290/Test.scala @@ -30,4 +30,16 @@ object Test extends App { println("====") println(valueOf[TextBlocks.Octal.type]) println("====") + println(hexdump(valueOf[TextBlocks.Octal.type])) + println("====") + println(hexdump(valueOf[TextBlocks.Zero.type].toString)) + println("====") + println(hexdump(valueOf[TextBlocks.Magic.type].toString)) + println("====") + println(hexdump(valueOf[TextBlocks.Maxie.type].toString)) + println("====") } + +def hexdump(s: String) = s.getBytes(io.Codec.UTF8.charSet) // java.nio.charset.StandardCharsets.UTF_8 + .map(b => f"${b & 0xff}%02x") + .mkString diff --git a/tests/run/t12290/TextBlocks.java b/tests/run/t12290/TextBlocks.java index 6a827923a052..9dd34e1546a5 100644 --- a/tests/run/t12290/TextBlocks.java +++ b/tests/run/t12290/TextBlocks.java @@ -81,4 +81,7 @@ class TextBlocks { """; final static String Octal = "X\040Y"; + final static char Zero = '\0'; + final static char Magic = '\52'; + final static char Maxie = '\377'; }