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
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@techtonik
Copy link

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 the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Sep 10, 2018
@ALTree ALTree added this to the Go1.12 milestone Sep 10, 2018
@agnivade
Copy link
Contributor

/cc @griesemer @mdempsky

@griesemer
Copy link
Contributor

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

@griesemer griesemer added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. labels Sep 12, 2018
@griesemer griesemer modified the milestones: Go1.12, Unplanned Sep 12, 2018
@gopherbot
Copy link

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

@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.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants