diff options
| author | griesemer <gri@golang.org> | 2017-10-05 14:20:51 -0700 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2017-10-06 16:35:44 +0000 |
| commit | b77d9fe0ead35a30cbe449ae805bc4a8770b4a68 (patch) | |
| tree | 589257d488792beb460382da82e3a4861d8d0cd3 | |
| parent | e33b01651cccce4293eb7a2ae7b40774e1dbeec9 (diff) | |
| download | go-b77d9fe0ead35a30cbe449ae805bc4a8770b4a68.tar.xz | |
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>
| -rw-r--r-- | src/cmd/compile/internal/gc/typecheck.go | 2 | ||||
| -rw-r--r-- | test/fixedbugs/bug289.go | 4 | ||||
| -rw-r--r-- | test/fixedbugs/bug487.go | 4 |
3 files changed, 5 insertions, 5 deletions
diff --git a/src/cmd/compile/internal/gc/typecheck.go b/src/cmd/compile/internal/gc/typecheck.go index a6c54f4569..ab2c77a3fb 100644 --- a/src/cmd/compile/internal/gc/typecheck.go +++ b/src/cmd/compile/internal/gc/typecheck.go @@ -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: diff --git a/test/fixedbugs/bug289.go b/test/fixedbugs/bug289.go index a3f729557c..3fc7fb2eef 100644 --- a/test/fixedbugs/bug289.go +++ b/test/fixedbugs/bug289.go @@ -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 } diff --git a/test/fixedbugs/bug487.go b/test/fixedbugs/bug487.go index 60a4ea9808..ab61a19a94 100644 --- a/test/fixedbugs/bug487.go +++ b/test/fixedbugs/bug487.go @@ -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 } |
