]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: better error message for assignment mismatches
authorgriesemer <gri@golang.org>
Thu, 5 Oct 2017 21:20:51 +0000 (14:20 -0700)
committerRobert Griesemer <gri@golang.org>
Fri, 6 Oct 2017 16:35:44 +0000 (16:35 +0000)
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>
src/cmd/compile/internal/gc/typecheck.go
test/fixedbugs/bug289.go
test/fixedbugs/bug487.go

index a6c54f4569f50560f3b074404cb1e1ff6a027dd8..ab2c77a3fb2079cfc6a73cd3d2d249d242829536 100644 (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:
index a3f729557cd5a339788e7111ed6ee99c6f56449e..3fc7fb2eeff7cf002d43bbfaedf4ed3d971baf3a 100644 (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
 }
index 60a4ea9808bf6630f1371885505fe94e8cb8292a..ab61a19a9454857c2c348b925c42b4c82ecab889 100644 (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
 }