go/types, types2: use "multiple-value" instead "n-valued" in error messages

This matches current compiler behavior.

For #55326.

Change-Id: I9ebe2914323072b5454fb9af2d15c9dd2d711bad
Reviewed-on: https://go-review.googlesource.com/c/go/+/434735
Run-TryBot: Robert Griesemer <gri@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
This commit is contained in:
Robert Griesemer 2022-09-26 11:47:22 -07:00 committed by Gopher Robot
parent 605148c0fb
commit 3b5188ed2c
9 changed files with 23 additions and 31 deletions

View File

@ -1860,11 +1860,7 @@ func (check *Checker) singleValue(x *operand) {
// tuple types are never named - no need for underlying type below
if t, ok := x.typ.(*Tuple); ok {
assert(t.Len() != 1)
if check.conf.CompilerErrorMessages {
check.errorf(x, _TooManyValues, "multiple-value %s in single-value context", x)
} else {
check.errorf(x, _TooManyValues, "%d-valued %s where single value is expected", t.Len(), x)
}
check.errorf(x, _TooManyValues, "multiple-value %s in single-value context", x)
x.mode = invalid
}
}

View File

@ -1803,11 +1803,7 @@ func (check *Checker) singleValue(x *operand) {
// tuple types are never named - no need for underlying type below
if t, ok := x.typ.(*Tuple); ok {
assert(t.Len() != 1)
if compilerErrorMessages {
check.errorf(x, _TooManyValues, "multiple-value %s in single-value context", x)
} else {
check.errorf(x, _TooManyValues, "%d-valued %s where single value is expected", t.Len(), x)
}
check.errorf(x, _TooManyValues, "multiple-value %s in single-value context", x)
x.mode = invalid
}
}

View File

@ -175,8 +175,8 @@ var (
func g() (a, b int) { return }
func _() {
_ = -g /* ERROR 2-valued g */ ()
_ = <-g /* ERROR 2-valued g */ ()
_ = -g /* ERROR multiple-value g */ ()
_ = <-g /* ERROR multiple-value g */ ()
}
// ~ is accepted as unary operator only permitted in interface type elements

View File

@ -120,8 +120,8 @@ func _(x, y string, z mystring) {
func f() (a, b int) { return }
func _(x int) {
_ = f /* ERROR 2-valued f */ () + 1
_ = x + f /* ERROR 2-valued f */ ()
_ = f /* ERROR 2-valued f */ () + f
_ = f /* ERROR 2-valued f */ () + f /* ERROR 2-valued f */ ()
_ = f /* ERROR multiple-value f */ () + 1
_ = x + f /* ERROR multiple-value f */ ()
_ = f /* ERROR multiple-value f */ () + f
_ = f /* ERROR multiple-value f */ () + f /* ERROR multiple-value f */ ()
}

View File

@ -554,7 +554,7 @@ func _calls() {
fi(1, 2.0, x, 3.14, "foo")
fi(g2())
fi(0, g2)
fi(0, g2 /* ERROR "2-valued g2" */ ())
fi(0, g2 /* ERROR "multiple-value g2" */ ())
}
func issue6344() {

View File

@ -61,10 +61,10 @@ func issue9473(a []int, b ...int) {
_ = append(f1())
_ = append(f2 /* ERROR cannot use .* in argument */ ())
_ = append(f2()... /* ERROR cannot use ... */ )
_ = append(f0(), f1 /* ERROR 2-valued f1 */ ())
_ = append(f0(), f2 /* ERROR 2-valued f2 */ ())
_ = append(f0(), f1 /* ERROR 2-valued f1 */ ()...)
_ = append(f0(), f2 /* ERROR 2-valued f2 */ ()...)
_ = append(f0(), f1 /* ERROR multiple-value f1 */ ())
_ = append(f0(), f2 /* ERROR multiple-value f2 */ ())
_ = append(f0(), f1 /* ERROR multiple-value f1 */ ()...)
_ = append(f0(), f2 /* ERROR multiple-value f2 */ ()...)
// variadic user-defined function
append_(f0())
@ -72,10 +72,10 @@ func issue9473(a []int, b ...int) {
append_(f1())
append_(f2 /* ERROR cannot use .* in argument */ ())
append_(f2()... /* ERROR cannot use ... */ )
append_(f0(), f1 /* ERROR 2-valued f1 */ ())
append_(f0(), f2 /* ERROR 2-valued f2 */ ())
append_(f0(), f1 /* ERROR 2-valued f1 */ ()...)
append_(f0(), f2 /* ERROR 2-valued f2 */ ()...)
append_(f0(), f1 /* ERROR multiple-value f1 */ ())
append_(f0(), f2 /* ERROR multiple-value f2 */ ())
append_(f0(), f1 /* ERROR multiple-value f1 */ ()...)
append_(f0(), f2 /* ERROR multiple-value f2 */ ()...)
}
// Check that embedding a non-interface type in an interface results in a good error message.

View File

@ -650,14 +650,14 @@ func issue11667() {
func issue11687() {
f := func() (_, _ int) { return }
switch f /* ERROR "2-valued f" */ () {
switch f /* ERROR "multiple-value f" */ () {
}
var x int
switch f /* ERROR "2-valued f" */ () {
switch f /* ERROR "multiple-value f" */ () {
case x:
}
switch x {
case f /* ERROR "2-valued f" */ ():
case f /* ERROR "multiple-value f" */ ():
}
}

View File

@ -39,7 +39,7 @@ var _ = f(0 /* ERROR cannot use 0 .* as \[\]chan int */ )
func swap[A, B any](a A, b B) (B, A) { return b, a }
var _ = swap /* ERROR single value is expected */ [int, float32](1, 2)
var _ = swap /* ERROR multiple-value */ [int, float32](1, 2)
var f32, i = swap[int, float32](swap[float32, int](1, 2))
var _ float32 = f32
var _ int = i

View File

@ -28,7 +28,7 @@ var _ = 1, 2 /* ERROR "extra init expr 2" */
var _, _ = 1 /* ERROR "cannot initialize [0-9]+ variables with [0-9]+ values" */
var _, _, _ /* ERROR "missing init expr for _" */ = 1, 2
var _ = g /* ERROR "2-valued g" */ ()
var _ = g /* ERROR "multiple-value g" */ ()
var _, _ = g()
var _, _, _ = g /* ERROR "cannot initialize [0-9]+ variables with [0-9]+ values" */ ()
@ -47,7 +47,7 @@ var (
_, _ = 1 /* ERROR "cannot initialize [0-9]+ variables with [0-9]+ values" */
_, _, _ /* ERROR "missing init expr for _" */ = 1, 2
_ = g /* ERROR "2-valued g" */ ()
_ = g /* ERROR "multiple-value g" */ ()
_, _ = g()
_, _, _ = g /* ERROR "cannot initialize [0-9]+ variables with [0-9]+ values" */ ()