Skip to content

Commit e340c62

Browse files
committed
Tweak java getlitch not to skip zero
1 parent 450d233 commit e340c62

File tree

4 files changed

+34
-2
lines changed

4 files changed

+34
-2
lines changed

compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala

+4-2
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ object JavaScanners {
439439
}
440440
oct.asInstanceOf[Char]
441441
end octal
442+
var skip = false
442443
def greatEscape: Char =
443444
nextChar()
444445
if '0' <= ch && ch <= '7' then octal
@@ -455,11 +456,12 @@ object JavaScanners {
455456
case '\\' => '\\'
456457
case CR | LF if inTextBlock =>
457458
if !scanOnly then nextChar()
459+
skip = true
458460
0
459461
case _ =>
460462
if !scanOnly then error("invalid escape character", charOffset - 1)
461463
ch
462-
if x != 0 then nextChar()
464+
if !skip then nextChar()
463465
x
464466
end greatEscape
465467

@@ -470,7 +472,7 @@ object JavaScanners {
470472
val res = ch
471473
nextChar()
472474
res
473-
if c != 0 && !scanOnly then putChar(c)
475+
if !skip && !scanOnly then putChar(c)
474476
end getlitch
475477

476478
/** Read a triple-quote delimited text block, starting after the first three double quotes.

tests/run/t12290.check

+8
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,11 @@ XY
6464
====
6565
X Y
6666
====
67+
582059
68+
====
69+
0
70+
====
71+
2a
72+
====
73+
c3bf
74+
====

tests/run/t12290/Test.scala

+19
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,23 @@ object Test extends App {
3030
println("====")
3131
println(valueOf[TextBlocks.Octal.type])
3232
println("====")
33+
println(hexdump(valueOf[TextBlocks.Octal.type]))
34+
println("====")
35+
println(hexdump(valueOf[TextBlocks.Zero.type].toString))
36+
println("====")
37+
println(hexdump(valueOf[TextBlocks.Magic.type].toString))
38+
println("====")
39+
println(hexdump(valueOf[TextBlocks.Maxie.type].toString))
40+
println("====")
3341
}
42+
43+
val printable = raw"\p{Print}".r
44+
45+
def hexdump(s: String) = s.getBytes(io.Codec.UTF8.charSet) // java.nio.charset.StandardCharsets.UTF_8
46+
.map(b => b.toInt.toHexString.takeRight(2)).mkString
47+
/*
48+
.map(b => b.toChar match {
49+
case c @ printable() => f"$c%2c"
50+
case _ => f"$b%02x"
51+
}).mkString
52+
*/

tests/run/t12290/TextBlocks.java

+3
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,7 @@ class TextBlocks {
8181
""";
8282

8383
final static String Octal = "X\040Y";
84+
final static char Zero = '\0';
85+
final static char Magic = '\52';
86+
final static char Maxie = '\377';
8487
}

0 commit comments

Comments
 (0)