Skip to content

Text block containing a comment-like line with " or \ fails with "Comment was not printed" #1112

Closed

Description

@2is10

Prettier-Java 2.11.0

Input:

class A {
  String s = """
    /* a "b" c */
    x""";
}

Output:

[error] A.java: Error: Comment "/* a "b" c */" was not printed. Please report this error!

Expected behavior:

class A {

  String s = """
  /* a "b" c */
  x""";
}

Text block content should never be treated as Java comments.


The same crash happens with a line comment or a backslash, as in these examples:

  String s = """
    // a "b
    x""";
  String s = """
    /* a \\n b */
    x""";
  String s = """
    // a \\ b
    x""";

A comment-like line without " or \, such as /* plain */, formats fine.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions