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/68690
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
griesemer 2017-10-05 14:20:51 -07:00 committed by Robert Griesemer
parent e33b01651c
commit b77d9fe0ea
3 changed files with 5 additions and 5 deletions

View File

@ -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:

View File

@ -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
}

View File

@ -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
}