Skip to content

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

@mdevan

Description

@mdevan

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions