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: misleading error message for index expression #49571

Closed
mdevan opened this issue Nov 13, 2021 · 1 comment
Closed

cmd/compile: misleading error message for index expression #49571

mdevan opened this issue Nov 13, 2021 · 1 comment
Milestone

Comments

@mdevan
Copy link

@mdevan mdevan commented Nov 13, 2021

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

$ go version
go version go1.17.2 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

What did you do?

In this code:

	if a, b := c["foo"]; b {
		fmt.Print(a)
	}

if the variable 'c' is not defined, these errors are reported:

./prog.go:8:10: assignment mismatch: 2 variables but 1 value
./prog.go:8:13: undefined: c

The first error message is misleading and redundant.

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

What did you expect to see?

Only the second error message (undefined: c).

What did you see instead?

As shown above.

@odeke-em
Copy link
Member

@odeke-em odeke-em commented Nov 13, 2021

Thank you @mdevan for reporting this issue! It is fixed for Go1.18 thanks be to the excellent work that @findleyr and @griesemer implemented this cycle.

$ go version && go run main.go 
go version devel go1.18-5344dcae41 Tue Nov 9 00:08:42 2021 +0000 darwin/amd64
# command-line-arguments
./main.go:8:13: undefined: c

You can experiment with the latest Go version by following https://pkg.go.dev/golang.org/dl/gotip#pkg-overview

$ go install golang.org/dl/gotip@latest
$ gotip download

I shall therefore close this issue, but please don't hesitate to reach out and file more bugs as you see them.

@odeke-em odeke-em added this to the Go1.18 milestone Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants