From: griesemer Date: Thu, 5 Oct 2017 21:20:51 +0000 (-0700) Subject: cmd/compile: better error message for assignment mismatches X-Git-Tag: go1.10beta1~838 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b77d9fe0ead35a30cbe449ae805bc4a8770b4a68;p=gostls13.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 --- 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 }