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

cmd/gofmt: strange indentation with trailing comments #20874

Closed
dsnet opened this issue Jun 30, 2017 · 2 comments
Closed

cmd/gofmt: strange indentation with trailing comments #20874

dsnet opened this issue Jun 30, 2017 · 2 comments

Comments

@dsnet
Copy link
Member

@dsnet dsnet commented Jun 30, 2017

Consider the following snippet:

package main

var x = 0 +
	1 +
		2 // C1
func main() { // C2
}

gofmt formats this code with two indents before the 2, when only one is expected such that it aligns with the 1 + on the previous line.

If you remove the "// C2", then it formats as you would expect:

package main

var x = 0 +
	1 +
	2 // C1
func main() {
}

You can see it happen on the playground: https://play.golang.org/p/FGRkk773Az

\cc @griesemer @bradfitz @odeke-em

@dsnet dsnet added the NeedsFix label Jun 30, 2017
@dsnet
Copy link
Member Author

@dsnet dsnet commented Jun 30, 2017

Wow, crazy. If you increase the length of the line with C2, the number of indents increase:

package main

var x = 0 +
	1 +
							2 // C1
func reallyReallyReallyReallyReallyReallyLongName() { // C2
}
@dsnet
Copy link
Member Author

@dsnet dsnet commented Jun 30, 2017

This is fixed on tip. Closing.

@dsnet dsnet closed this Jun 30, 2017
@golang golang locked and limited conversation to collaborators Jun 30, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.