Skip to content

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

Closed

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.

Activity

  1. odeke-em commented on Nov 13, 2021

    @odeke-em
    Member

    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.

  2. added this to the Go1.18 milestone on Nov 13, 2021
  3. locked and limited conversation to collaborators on Nov 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions