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>
// 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
}
}
// 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
}
}
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
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 */ ()
}
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() {
_ = 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())
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.
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" */ ():
}
}
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
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" */ ()
_, _ = 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" */ ()