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

Comments

Projects
None yet
3 participants
@dave
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

This comment has been minimized.

Show comment
Hide comment
@agnivade

agnivade Oct 2, 2018

Member

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

Member

agnivade commented Oct 2, 2018

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

@dave

This comment has been minimized.

Show comment
Hide comment
@dave

dave Oct 2, 2018

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@agnivade

agnivade Oct 2, 2018

Member

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

@griesemer

Member

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

@dave

This comment has been minimized.

Show comment
Hide comment
@dave

dave Oct 2, 2018

Contributor

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.

Contributor

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 and removed NeedsDecision labels Oct 2, 2018

@griesemer griesemer self-assigned this Oct 2, 2018

@griesemer

This comment has been minimized.

Show comment
Hide comment
@griesemer

griesemer Oct 2, 2018

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.

Contributor

griesemer commented Oct 2, 2018

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