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: remove key literal with triple nested map #29450

Open
hajimehoshi opened this issue Dec 29, 2018 · 2 comments
Open

cmd/gofmt: remove key literal with triple nested map #29450

hajimehoshi opened this issue Dec 29, 2018 · 2 comments

Comments

@hajimehoshi
Copy link
Member

@hajimehoshi hajimehoshi commented Dec 29, 2018

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

$ go version
go version go1.11.2 darwin/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="/Users/hajimehoshi/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/hajimehoshi/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/ht/ky_bwgzs4bd5z1hh02k34x_h0000gn/T/go-build035827831=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Execute gofmt -s -w main.go with the below main.go:

package main

var foo = map[bool]map[bool]map[bool]int{
        false: {
                false: map[bool]int{false: 0, true: 1},
                true:  map[bool]int{false: 0, true: 1},
        },
        true: {
                false: {false: 0, true: 1},
                true:  {false: 0, true: 1},
        },
}

What did you expect to see?

main.go should change like below:

package main

var foo = map[bool]map[bool]map[bool]int{
        false: {
                false: {false: 0, true: 1},
                true:  {false: 0, true: 1},
        },
        true: {
                false: {false: 0, true: 1},
                true:  {false: 0, true: 1},
        },
}

What did you see instead?

main.go did not change.

@agnivade
Copy link
Contributor

@agnivade agnivade commented Dec 29, 2018

I think this is more of a feature request than a bug.

/cc @griesemer

@agnivade agnivade changed the title cmd/gofmt: fail to remove key literal with triple nested map cmd/gofmt: remove key literal with triple nested map Dec 29, 2018
@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 29, 2018

There are many such code simplifications that we could do (or not do). It's not clear that they should be in gofmt. A separate tool might be the better solution.

Also, in general, getting this to work right for all cases will require type information which is not available in gofmt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.