Skip to content

Missing newline with labeled block inside control flow #1641

Open
@munificent

Description

@munificent

Labels are virtually unused, but they still need to be formatted correctly. If you format:

main() {
  if (c) L: {s;}
}

The formatter produces:

main() {
  if (c)   L:
    {
      s;
    }
}

The more indentation, the more spaces before the label, even though it doesn't put a newline there. So if you format:

main() {
  {
    {
      {
        if (c) L: {s;}
      }
    }
  }
}

You get:

main() {
  {
    {
      {
        if (c)         L:
          {
            s;
          }
      }
    }
  }
}

Similar behavior happens with loops:

main() {
  {
    {
      {
        for (;;) L: {s;}

        while (c) L: {s;}
      }
    }
  }
}

Produces:

main() {
  {
    {
      {
        for (;;)         L:
          {
            s;
          }

        while (c)         L:
          {
            s;
          }
      }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions