Skip to content

Commit

Permalink
Backport "Tweak java getlitch not to skip zero" to LTS (#20613)
Browse files Browse the repository at this point in the history
Backports #18491 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
  • Loading branch information
WojciechMazur authored Jun 20, 2024
2 parents ff8acef + 2ed285b commit 90928a4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/JavaScanners.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions tests/run/t12290.check
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,11 @@ XY
====
X Y
====
582059
====
00
====
2a
====
c3bf
====
12 changes: 12 additions & 0 deletions tests/run/t12290/Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions tests/run/t12290/TextBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

0 comments on commit 90928a4

Please sign in to comment.