Skip to content
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

Missing newline with labeled block inside control flow #1641

Open
munificent opened this issue Feb 4, 2025 · 1 comment
Open

Missing newline with labeled block inside control flow #1641

munificent opened this issue Feb 4, 2025 · 1 comment

Comments

@munificent
Copy link
Member

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;
          }
      }
    }
  }
}
@munificent
Copy link
Member Author

A labeled else block is also a little wonky, though honestly I'm not sure what the right output should be here:

Before:

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

After:

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

At least it does put the newline here. This formatting might be the best we can do.

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

No branches or pull requests

1 participant