You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After formatting the above code with gofmt, I would expect it to be formatted similarly to when any other piece of code is commented out, so it should be:
I'm pretty sure I know why it happens. It has to do with go/printer detecting a so called "line of stars" style of comments, which normally look like this:
* Check for vertical "line of stars" and correct prefix accordingly.
*/
lineOfStars:=false
ifi:=strings.Index(prefix, "*"); i>=0 {
// Line of stars present.
ifi>0&&prefix[i-1] ==' ' {
i--// remove trailing blank from prefix so stars remain aligned
}
prefix=prefix[0:i]
lineOfStars=true
.
However, in this case, it's not a comment block because there is no space after the * as in normally formatted comments, it's just commented out code that happens to falsely trigger the line of stars comment block handling.
The text was updated successfully, but these errors were encountered:
I probably went overboard trying to recognize the "Line of stars".
This might be easily fixable by recognizing the "Line of stars" only if stars followed by text have a blank after the star. Of course, for "* p = 0" this would still fail, but people tend to write "p" rather than " p".
Another option might be to simply remove the "Line of stars" logic.
This might be easily fixable by recognizing the "Line of stars" only if stars followed by text have a blank after the star. Of course, for "* p = 0" this would still fail, but people tend to write "p" rather than " p".
Yep.
Another option might be to simply remove the "Line of stars" logic.
I was thinking that too, and if possible, I think it's a better solution because it's a chance to make Go a little simpler. I've seen a lot of Go code, and line of stars is exceedingly rare. It seems it'd be better not to have it.
Not urgent.
Agreed. I filed this simply to track the issue, since I had encountered it just recently.
What version of Go are you using (go version)?
What operating system and processor architecture are you using?
OS X 10.10.5, amd64.
What did you do?
Consider the following program:
If you comment out the first block of code and run
gofmt
on it, you get:However, if you comment out the second block of code like this:
What did you expect to see?
After formatting the above code with
gofmt
, I would expect it to be formatted similarly to when any other piece of code is commented out, so it should be:What did you see instead?
Which is not consistent with anything.
I'm pretty sure I know why it happens. It has to do with go/printer detecting a so called "line of stars" style of comments, which normally look like this:
See relevant code at
go/src/go/printer/printer.go
Lines 529 to 539 in 467a2cb
However, in this case, it's not a comment block because there is no space after the * as in normally formatted comments, it's just commented out code that happens to falsely trigger the line of stars comment block handling.
The text was updated successfully, but these errors were encountered: