Navigation Menu

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/go: cannot use map index special form in return statements #25442

Closed
jamie-digital opened this issue May 17, 2018 · 1 comment
Closed

cmd/go: cannot use map index special form in return statements #25442

jamie-digital opened this issue May 17, 2018 · 1 comment

Comments

@jamie-digital
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go1.10

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

all

What did you do?

When storing the results into two variables, the special form of a map index operation can return two parts. The same is not true in a return statement, even when the function signature makes this unambiguous.

https://play.golang.org/p/mmJ8ZlWC2yn

What did you expect to see?

I would expect CheckCache_works and CheckCache_shouldWork to function identically.

What did you see instead?

gc refuses to compile the return statement, saying:

prog.go:15:2: not enough arguments to return
	have (int)
	want (int, bool)

Apologies if this duplicates a previous issue. I found searching for and naming this issue pretty hard.

@ianlancetaylor
Copy link
Contributor

That is how the language works, as defined by the language spec (https://golang.org/ref/spec). The special , ok form of a map index is only available in an assignment or initialization, as documented at https://golang.org/ref/spec#Index_expressions .

If you want to propose that the language be changed, please follow the proposal process documented at https://github.com/golang/proposal/blob/master/README.md . Thanks.

@golang golang locked and limited conversation to collaborators May 17, 2019
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

3 participants