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

Closed
hajimehoshi opened this issue Dec 29, 2018 · 3 comments
Closed

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

hajimehoshi opened this issue Dec 29, 2018 · 3 comments
Labels
FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@hajimehoshi
Copy link
Member

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 commented Dec 29, 2018

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

/cc @griesemer

@agnivade agnivade added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. FeatureRequest labels Dec 29, 2018
@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 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.

@seankhliao
Copy link
Member

Sounds like this is working as intended

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Aug 20, 2022
@golang golang locked and limited conversation to collaborators Aug 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FeatureRequest FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

5 participants