Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: error for unexpected return values does not say 'return' #50653

Closed
rsc opened this issue Jan 17, 2022 · 1 comment
Closed

cmd/compile: error for unexpected return values does not say 'return' #50653

rsc opened this issue Jan 17, 2022 · 1 comment
Labels
NeedsFix release-blocker
Milestone

Comments

@rsc
Copy link
Contributor

@rsc rsc commented Jan 17, 2022

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.

@rsc rsc self-assigned this Jan 17, 2022
@rsc rsc added the NeedsFix label Jan 17, 2022
@rsc rsc added this to the Go1.18 milestone Jan 17, 2022
@gopherbot
Copy link

@gopherbot gopherbot commented Jan 18, 2022

Change https://golang.org/cl/379116 mentions this issue: cmd/compile, go/types: restore 'too many return values' error for func with no results

jproberts pushed a commit to jproberts/go that referenced this issue Jun 21, 2022
…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 ()

Fixes golang#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>
@rsc rsc removed their assignment Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix release-blocker
Projects
None yet
Development

No branches or pull requests

2 participants