Skip to content

cmd/gofmt: inconsistent indentation for comments inside switch-case #30327

@subsr97

Description

@subsr97

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

$ go version
go version go1.11.4 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/local/ZOHOCORP/mani-pt2396/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/local/ZOHOCORP/mani-pt2396/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build688297931=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Commented out the last case of switch with line or block comment(s).

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

What did you expect to see?

The last case(s) to be in their place and not go inside the scope of the previous case.

	switch val {
	case foo1:
		foo()
	case foo2:
		foo()
	// case bar:
		// bar()
	}

	switch val {
	case foo1:
		foo()
	case foo2:
		foo()
	/* case bar:
		// bar()*/
	}

What did you see instead?

The last case(s) is aligned as if it is inside the scope of the previous case.

	switch val {
	case foo1:
		foo()
	case foo2:
		foo()
		// case bar:
		// bar()
	}

	switch val {
	case foo1:
		foo()
	case foo2:
		foo()
		/* case bar:
		// bar()*/
	}

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions