checkassign(n, n.Left)
if n.Right != nil && n.Right.Type != nil {
if n.Right.Type.IsFuncArgStruct() {
- yyerror("assignment mismatch: 1 variable but %d values", n.Right.Type.NumFields())
+ yyerror("assignment mismatch: 1 variable but %v returns %d values", n.Right.Left, n.Right.Type.NumFields())
// Multi-value RHS isn't actually valid for OAS; nil out
// to indicate failed typechecking.
n.Right.Type = nil
}
mismatch:
- yyerror("assignment mismatch: %d variables but %d values", cl, cr)
+ switch r.Op {
+ default:
+ yyerror("assignment mismatch: %d variable but %d values", cl, cr)
+ case OCALLFUNC, OCALLMETH, OCALLINTER:
+ yyerror("assignment mismatch: %d variables but %v returns %d values", cl, r.Left, cr)
+ }
// second half of dance
out:
package p
-var x int = three() // ERROR "1 variable but 3 values"
+var x int = three() // ERROR "assignment mismatch: 1 variable but three returns 3 values"
func f() {
- var _ int = three() // ERROR "1 variable but 3 values"
- var a int = three() // ERROR "1 variable but 3 values"
- a = three() // ERROR "1 variable but 3 values"
- b := three() // ERROR "1 variable but 3 values"
+ var _ int = three() // ERROR "assignment mismatch: 1 variable but three returns 3 values"
+ var a int = three() // ERROR "assignment mismatch: 1 variable but three returns 3 values"
+ a = three() // ERROR "assignment mismatch: 1 variable but three returns 3 values"
+ b := three() // ERROR "assignment mismatch: 1 variable but three returns 3 values"
_, _ = a, b
}
--- /dev/null
+// errorcheck
+
+// Copyright 2018 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package main
+
+var a = twoResults() // ERROR "assignment mismatch: 1 variable but twoResults returns 2 values"
+var b, c, d = twoResults() // ERROR "assignment mismatch: 3 variables but twoResults returns 2 values"
+var e, f = oneResult() // ERROR "assignment mismatch: 2 variables but oneResult returns 1 values"
+
+func twoResults() (int, int) {
+ return 1, 2
+}
+
+func oneResult() int {
+ return 1
+}