p1% cat /tmp/x.go
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 }
p1% go tool compile /tmp/x.go
/tmp/x.go:3:33: no result values expected <<<
/tmp/x.go:4:33: no result values expected <<<
/tmp/x.go:5:26: not enough return values
have ()
want (int)
/tmp/x.go:6:36: too many return values
have (number, number)
want (int)
/tmp/x.go:7:26: not enough return values
have ()
want (int, int)
/tmp/x.go:8:33: not enough return values
have (number)
want (int, int)
p1%
The marked messages that say 'result values' should be rewritten to say 'return values',
both for consistency with the others and for clarity.
The simplest fix is probably to stop treating f0_1 and f0_2 as a special case
and let the general 'too many return values' printer handle them, just like f1_0 and f2_0` are not special cases and are handled by the general 'not enough return values' printer.
I know there's still plenty of generics work left in the type checker.
I can take care of this one myself this week.
The text was updated successfully, but these errors were encountered:
…c 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 ()
Fixesgolang#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>
The marked messages that say 'result values' should be rewritten to say 'return values',
both for consistency with the others and for clarity.
The simplest fix is probably to stop treating
f0_1
andf0_2
as a special caseand let the general 'too many return values' printer handle them, just like
f1_0 and
f2_0` are not special cases and are handled by the general 'not enough return values' printer.I know there's still plenty of generics work left in the type checker.
I can take care of this one myself this week.
The text was updated successfully, but these errors were encountered: