Commit b77d9fe0 authored by griesemer's avatar griesemer Committed by Robert Griesemer

cmd/compile: better error message for assignment mismatches

Keep left-to-right order when referring to the number of
variables and values involved.

Fixes #22159.

Change-Id: Iccca12d3222f9d5e049939a9ccec07513c393faa
Reviewed-on: https://go-review.googlesource.com/68690Reviewed-by: 's avatarRuss Cox <rsc@golang.org>
parent e33b0165
......@@ -3426,7 +3426,7 @@ func typecheckas2(n *Node) {
}
mismatch:
yyerror("cannot assign %d values to %d variables", cr, cl)
yyerror("assignment mismatch: %d variables but %d values", cl, cr)
// second half of dance
out:
......
......@@ -9,14 +9,14 @@
package main
func f1() {
a, b := f() // ERROR "cannot assign|does not match"
a, b := f() // ERROR "assignment mismatch|does not match"
_ = a
_ = b
}
func f2() {
var a, b int
a, b = f() // ERROR "cannot assign|does not match"
a, b = f() // ERROR "assignment mismatch|does not match"
_ = a
_ = b
}
......
......@@ -14,8 +14,8 @@ func G() (int, int, int) {
}
func F() {
a, b := G() // ERROR "cannot assign"
a, b = G() // ERROR "cannot assign"
a, b := G() // ERROR "assignment mismatch"
a, b = G() // ERROR "assignment mismatch"
_, _ = a, b
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment