mirror of https://github.com/golang/go.git
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:
parent
e33b01651c
commit
b77d9fe0ea
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue