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: incorrect indentation of comments for LabeledStmt #27964

Open
dave opened this issue Oct 2, 2018 · 5 comments
Open

cmd/gofmt: incorrect indentation of comments for LabeledStmt #27964

dave opened this issue Oct 2, 2018 · 5 comments
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@dave
Copy link
Contributor

dave commented Oct 2, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.11

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

darwin/amd64

What did you do?

If a LabeledStmt has an inline comment before and after the Colon, then an inline comment on the previous line will be indented incorrectly:

https://play.golang.org/p/mSDEYsc_34O

This code should not change with gofmt:

package main

func main() {

	/* comment */
L /* long comment */ : /* comment */
	print("foo")

	goto L

}

... however it changes to:

package main

func main() {

			/* comment */
L /* long comment */ : /* comment */
	print("foo")

	goto L

}
@agnivade
Copy link
Contributor

agnivade commented Oct 2, 2018

Curious to know - did you encounter this in a real-world code ?

@dave
Copy link
Contributor Author

dave commented Oct 2, 2018

No, not real-world code. I'm analysing all the positions that gofmt allows comments to be attached to the AST - see: https://github.com/dave/dst/blob/remove-doc-comment/gendst/postests/position-tests.go#L112-L115

@agnivade
Copy link
Contributor

agnivade commented Oct 2, 2018

I see. gofmt's heuristics are tuned for real world code. I wonder whether we should tackle a corner case like this.

@griesemer

@agnivade agnivade added this to the Unplanned milestone Oct 2, 2018
@agnivade agnivade added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Oct 2, 2018
@dave
Copy link
Contributor Author

dave commented Oct 2, 2018

Yup agreed - unlikely to come up in normal use, but it's the only formatting anomaly I've found yet, so I thought I'd mention it. I certainly wouldn't be too upset if this didn't get fixed.

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Oct 2, 2018
@griesemer griesemer self-assigned this Oct 2, 2018
@griesemer
Copy link
Contributor

It shouldn't be too hard to break alignment before a label. Assigning to myself so it stays in my radar but unlikely to get addressed anytime soon. Not important.

Thanks for reporting this irregularity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants