-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: confusing error message for 'a == x && b = y' #36858
Comments
go/types says |
I would like to have a look on this issue. |
I thought the original error message was pretty good. It is just being applied too broadly. It should read something like:
And have its location be that of b = “b”, not of the entire conjunction. |
It seems that the parser think the |
@josharian This is probably a simple fix for binary op:
not sure it's applied for unary op or not 🤔 |
I don’t know much about the parser. Maybe mail that as a CL and discuss with mdempsky or gri? In any case it is easier to discuss diffs in a CL. |
It seems that "help wanted" is no more required. I let Cuonlm finalize the fix. |
Related #23385 Should we fix this @griesemer ? |
@cuonglm It would be nice to fix this as it is probably a common typo. But at the same time it's subtle to get it right w/o going overboard. Your tentative patch seems reasonable. How about just highlighting the LHS and RHS of the assignment better with parentheses? For instance if the error message were: syntax error: assignment (a == "a" && b) = "b" used as value That is, we put parentheses around expressions if they are complex? (Needless to say that this is not even a valid assignment, but I don't think it's worthwhile spending code on figuring this out in the parser.) Even simpler, maybe it is good enough to take the current approach and just syntaxErrorAt and use the position of the |
@cuonglm I assigned myself to this just so I can keep track of it. Feel free to go ahead for now. |
Change https://golang.org/cl/218337 mentions this issue: |
@cuonglm Since I was already investigating this a bit more, I just sent out at CL. |
The conjunction isn't an assignment; the second conjunct is.
The text was updated successfully, but these errors were encountered: