]> Cypherpunks repositories - gostls13.git/commit
cmd/compile, go/types: restore 'too many return values' error for func with no results
authorRuss Cox <rsc@golang.org>
Tue, 18 Jan 2022 15:31:59 +0000 (10:31 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 18 Jan 2022 21:43:02 +0000 (21:43 +0000)
commitcf5d73e8a2ba8d382278c7f490db61e513768159
treeb798955c6dd1edd7ba6cfea47a948d65b39d638b
parent71888fe4b0d804f44371944f93f12442a6b0a862
cmd/compile, go/types: restore 'too many return values' error for func with no results

Currently the code handles the case of returning values from
a function with no result parameters as a special case.
Consider this input:

package p

func f0_2()            { return 1, 2 }
func f0_1()            { return 1 }
func f1_0() int        { return }
func f1_2() int        { return 1, 2 }
func f2_0() (int, int) { return }
func f2_1() (int, int) { return 1 }

The errors are:

x.go:3:33: no result values expected   <<<
x.go:4:33: no result values expected   <<<
x.go:5:26: not enough return values
have ()
want (int)
x.go:6:36: too many return values
have (number, number)
want (int)
x.go:7:26: not enough return values
have ()
want (int, int)
x.go:8:33: not enough return values
have (number)
want (int, int)

There are two problems with the current special case emitting the
errors on the marked line:

1. It calls them 'result values' instead of 'return values'.
2. It doesn't show the type being returned, which can be useful to programmers.

Using the general case solves both these problems,
so this CL removes the special case and calls the general case instead.

Now those two errors read:

x.go:3:33: too many return values
have (number, number)
want ()
x.go:4:33: too many return values
have (number)
want ()

Fixes #50653.

Change-Id: If6b47dcece14ed4febb3a2d3d78270d5be1cb24d
Reviewed-on: https://go-review.googlesource.com/c/go/+/379116
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
src/cmd/compile/internal/types2/stmt.go
src/cmd/compile/internal/types2/testdata/check/stmt0.src
src/cmd/compile/internal/types2/testdata/check/vardecl.src
src/go/types/stmt.go
src/go/types/testdata/check/stmt0.src
src/go/types/testdata/check/vardecl.src
test/fixedbugs/issue4215.go
test/fixedbugs/issue48834.go