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: "1 variable but %d values" to "1 variable but %d return values" #27595

Closed
techtonik opened this issue Sep 10, 2018 · 3 comments
Closed

Comments

@techtonik
Copy link

@techtonik techtonik commented Sep 10, 2018

This is a followup to #26616 which changed error message for this case:

bar := bufio.NewReader(...)
line := bar.ReadString()

from multiple-value bar.ReadString() in single-value context to 1 variable but 2 values.

In Python, if function returns multiple arguments (a tuple), it is completely okay to assign it to one variable:

>>> def xxx():
...   return 1,2
... 
>>> a = xxx()
>>> b, c = xxx()
>>> a
(1, 2)
>>> b
1
>>> c
2

Therefore if a Python coder like me is reading the Go code, it is not completely obvious what is going on, which was the reason to fill #26616. The error message that fixes #26616 is good, but could be improved to include return values for explicit context that the error cause is in return type of the function and not in the assignment statement.

@ALTree ALTree added this to the Go1.12 milestone Sep 10, 2018
@agnivade

This comment has been minimized.

Copy link
Contributor

@agnivade agnivade commented Sep 12, 2018

@griesemer

This comment has been minimized.

Copy link
Contributor

@griesemer griesemer commented Sep 12, 2018

I'm ok with making the error message more specific in case of a return statement. Not urgent.

@griesemer griesemer added NeedsFix and removed NeedsDecision labels Sep 12, 2018
@griesemer griesemer modified the milestones: Go1.12, Unplanned Sep 12, 2018
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Sep 15, 2018

Change https://golang.org/cl/135575 mentions this issue: cmd/compile: using more specific error message for assignment mismatch

@gopherbot gopherbot closed this in ae9c822 Sep 27, 2018
@golang golang locked and limited conversation to collaborators Sep 27, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.