-
Notifications
You must be signed in to change notification settings - Fork 18.1k
cmd/gofmt: rewrite Allman brace style, even if it doesn't compile? #34942
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
Comments
Note that func main() is valid Go to indicate that the function We could add a special case in gofmt for a function declaration followed by a block enclosed in curly braces, but it wouldn't be all that simple. |
This program doesn't compile. AFAIR, |
To @griesemer for decision. |
As has been already stated, func main()
{ ... } which is the same as The parser could possibly recognize the case of a stand-alone block (at the package level) preceded by a body-less function header, report an error, but assume the writer meant the "correct" program. We do this in other places in the parser, for better error recovery. This would lead to a better experience for the programmer, which is what we generally strive for. But the program would still be incorrect (the parser must report an error), and I filed #34946 to look into improved parsing. But even with that, |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I have a simple hello world program like this:
To fix the formatting I ran this:
What did you expect to see?
I expected the file to change to this:
What did you see instead?
hello.go:6:1: expected declaration, found '{'
Also, the file has not been changed at all.
The text was updated successfully, but these errors were encountered: