Skip to content

cmd/compile: confusing error in multiple assignment #78884

@rsc

Description

@rsc

Reduced from a larger program where the error was more confusing:

$ cat /tmp/x.go
package p

func f() (int, bool) { return 1, false }

func g() {
	var s string
	s, b := f()
	_, _ = s,b
}
$ GOTOOLCHAIN=go1.16 go tool compile /tmp/x.go
/tmp/x.go:7:7: cannot assign int to s (type string) in multiple assignment
$ GOTOOLCHAIN=go1.17 go tool compile /tmp/x.go
/tmp/x.go:7:7: cannot assign int to s (type string) in multiple assignment
/tmp/x.go:7:7: cannot use int value as type string in assignment
$ GOTOOLCHAIN=go1.18 go tool compile /tmp/x.go
/tmp/x.go:7:10: cannot use f() (value of type int) as type string in assignment
$ GOTOOLCHAIN=go1.26.0 go tool compile /tmp/x.go
/tmp/x.go:7:10: cannot use f() (value of type int) as string value in assignment
$ 

Note that Go 1.16 correctly the context "in multiple assignment".
Go 1.17 added a redundant error message.
Go 1.18 merged the two redundant error messages but at a loss of clarity:

  • It removed the word "multiple" from "in multiple assignment".
  • It falsely claims that f() is a "value of type int", despite f returning multiple values.

/cc @griesemer

Metadata

Metadata

Assignees

Labels

BadErrorMessageIssues related compiler error messages that should be better.BugReportIssues describing a possible bug in the Go implementation.NeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

Todo

Relationships

None yet

Development

No branches or pull requests

Issue actions