Skip to content

Java text block parser mangles a char on escaped eol #12575

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

Closed
som-snytt opened this issue Apr 7, 2022 · 4 comments · Fixed by scala/scala#10024
Closed

Java text block parser mangles a char on escaped eol #12575

som-snytt opened this issue Apr 7, 2022 · 4 comments · Fixed by scala/scala#10024
Assignees
Labels
Milestone

Comments

@som-snytt
Copy link

som-snytt commented Apr 7, 2022

Reproduction steps

Scala version: 2.13.8

    final static String simpleString = """
X\
Y
""";

Problem

The test sees

00000360  0a 22 22 22 3b 0a 0a 3d  3d 3d 3d 0a 00 59 0a 0a  |.""";..====..Y..|
00000370  3d 3d 3d 3d 0a 0a 3d 3d  3d 3d 0a                 |====..====.|

or

====
^@Y

====

instead of expected XY. The existing test drops a space char that is hard to spot. (Edit: now I count 8 spaces. Space blindness?)

@som-snytt som-snytt self-assigned this Apr 7, 2022
@som-snytt
Copy link
Author

Visible in -Vprint:parser

 <static> val s: String("\u0000Y\n") = _;

@SethTisue
Copy link
Member

SethTisue commented Apr 19, 2022

Which test, where is the test?

Does this affect anything other than the -Vprint:parser output?

The only scenario Dale or I can think of offhand where it might be user-visible is constant folding? Do we constant-fold from Java sources?

cc @harpocrates

@SethTisue SethTisue added this to the Backlog milestone Apr 19, 2022
@som-snytt
Copy link
Author

@som-snytt
Copy link
Author

som-snytt commented Aug 31, 2023

Following up, dotty had a related bug, and I see I did not answer the question about visibility.

➜  i18490 cat Z.java

public class Z {

  public static final char X = '\52';  // 42 decimal or '*'

}
➜  i18490 cat Y.scala

class Y {
  final val y = Z.X + 1
}
➜  i18490 scalac Y.scala Z.java
➜  i18490 scala
Welcome to Scala 2.13.11 (OpenJDK 64-Bit Server VM, Java 20.0.1).
Type in expressions for evaluation. Or try :help.

scala> new Y().y
val res0: Int = 43

scala> new Y().y.toChar
val res1: Char = +

scala> Z.X   // no Z.class
       ^
       error: not found: value Z

scala> '\52'  // today I needed quickfix in REPL
        ^
       error: octal escape literals are unsupported: use \u002a instead

scala> '\u002a'
val res3: Char = *

scala> '\u002a'.toInt
val res4: Int = 42

also javap

  public final int y();
    descriptor: ()I
    flags: (0x0011) ACC_PUBLIC, ACC_FINAL
    Code:
      stack=1, locals=1, args_size=1
         0: bipush        43
         2: ireturn

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants