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/compile: confusing assignment mismatch error when indexing map with invalid key #50762

Open
Snaipe opened this issue Jan 22, 2022 · 0 comments
Open
Labels
NeedsInvestigation
Milestone

Comments

@Snaipe
Copy link

@Snaipe Snaipe commented Jan 22, 2022

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

$ go version
go version go1.17.6 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
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/snaipe/.local/var/cache/go-build"
GOENV="/home/snaipe/.local/etc/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/snaipe/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/snaipe/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.17.6"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build2452324536=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Compiling this invalid program: https://play.golang.com/p/QWTPYt1MIep

... yields the following error:

./prog.go:5:8: assignment mismatch: 2 variables but 1 value
./prog.go:5:13: undefined: invalid

While the second error is completely reasonable, and probably what I would expect to see first and foremost, the first error is rather confusing. When fixing compile errors with a lot more messages, and getting a bit tunnel-visioned on fixing them one after the other, I was left wondering what was wrong with my program and attempting to change some variable names in hope of fixing it, only to realize a couple of minutes later that the undefined key was the actual issue.

This is of course pretty minor, but I wish the compiler hadn't shown me the first error since it threw me for a loop.

@ianlancetaylor ianlancetaylor added the NeedsInvestigation label Jan 23, 2022
@ianlancetaylor ianlancetaylor added this to the Backlog milestone Jan 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

2 participants