What version of Go are you using (go version)?
go version go1.10.2 darwin/amd64
Does this issue reproduce with the latest release?
Yep
What operating system and processor architecture are you using (go env)?
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/matt/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/matt/Dev"
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/d4/3d8k5bgd62v9h2c5f05xkyx80000gn/T/go-build921281437=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Started writing an else statement but got distracted fixing an issue elsewhere in the program and didn't finish the statement. Definitely my bad! However, gofmt made this bug a little harder to find:
https://play.golang.org/p/AdIDE1dT9Sd
Notice that the next statement is an if, with a comment between them. Because of the comment. go fmt didn't move the if up to the line with the else. That seems correct, however, since it is technically a continuation of the else, indenting the if would have been helpful for catching it.
What did you expect to see?
...
} else
// unfinished statement above
if b == 2 {
fmt.Println("b is 2")
}
...
What did you see instead?
...
} else
// unfinished statement above
if b == 2 {
fmt.Println("b is 2")
}
...
This is just a proposed enhancement -- not urgent, and definitely still my fault for not finishing a line I started -- but if gofmt could figure this out and cue me in by indenting, that would be helpful. :)
Edit: Seems similar to #20562 -- at least one of the comments there mentions the same issue, it looks like. Feel free to close if you think this is a duplicate. I can't quite tell if that's a separate formatting issue originally...
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
Yep
What operating system and processor architecture are you using (
go env)?What did you do?
Started writing an
elsestatement but got distracted fixing an issue elsewhere in the program and didn't finish the statement. Definitely my bad! However, gofmt made this bug a little harder to find:https://play.golang.org/p/AdIDE1dT9Sd
Notice that the next statement is an
if, with a comment between them. Because of the comment.go fmtdidn't move theifup to the line with theelse. That seems correct, however, since it is technically a continuation of theelse, indenting theifwould have been helpful for catching it.What did you expect to see?
What did you see instead?
This is just a proposed enhancement -- not urgent, and definitely still my fault for not finishing a line I started -- but if
gofmtcould figure this out and cue me in by indenting, that would be helpful. :)Edit: Seems similar to #20562 -- at least one of the comments there mentions the same issue, it looks like. Feel free to close if you think this is a duplicate. I can't quite tell if that's a separate formatting issue originally...