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: bad return shows <T> in type list #19012

Closed
rsc opened this issue Feb 9, 2017 · 4 comments
Closed

cmd/compile: bad return shows <T> in type list #19012

rsc opened this issue Feb 9, 2017 · 4 comments
Milestone

Comments

@rsc
Copy link
Contributor

rsc commented Feb 9, 2017

$ cat /tmp/x.go
package p

func f(x int, y uint) {
	z := x - y
	return x > z
}
$ go tool compile -S /tmp/x.go
/tmp/x.go:4: invalid operation: x - y (mismatched types int and uint)
/tmp/x.go:5: too many arguments to return
	have (<T>)
	want ()

The problem is that z's type is not known, because x-y does not type check
(already reported), and I guess that makes x > z's type not known,
which in turn displays as <T>.

But since the type of the result is not known at all, probably
it's safe not to complain about the argument count for the return at all.

So probably the entire error at line 5 should be suppressed.

/cc @griesemer @mdempsky

@rsc rsc added this to the Go1.9 milestone Feb 9, 2017
@josharian
Copy link
Contributor

cc @odeke-em

@odeke-em
Copy link
Member

Thanks for the shoutout as always @josharian 🙏🏾

@rsc in this case we already got an error on line 4, but am thinking if we suppress the one on
line 5, in the future if we haven't previously encountered an error or if the type is unknown with no
previous error. In cases where the type is unknown, perhaps we can change the message to be like it was in issue #4215 before CL https://go-review.googlesource.com/25156
so that error message will be

$ go tool compile -S /tmp/x.go
/tmp/x.go:4: invalid operation: x - y (mismatched types int and uint)
/tmp/x.go:5: too many arguments to return

and we can still indicate to them that there is an error on that line.

What do y'all think?

@odeke-em
Copy link
Member

I've mailed https://go-review.googlesource.com/36806.

@gopherbot
Copy link

CL https://golang.org/cl/36806 mentions this issue.

@odeke-em odeke-em self-assigned this Feb 22, 2017
@golang golang locked and limited conversation to collaborators Feb 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants