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: "used as value" syntax error reports the entire expression #23385
Comments
I agree that the error message is misleading. That said, it is not as wrong as it seems: Syntactically, this is not an expression but an assignment: For the reference, gccgo complains with:
Leaving open for now; perhaps there's a better way to report this. |
I thought about that possibility for a bit before posting, but convinced myself that it wasn't the case because then the left part of an assignment would be an invalid node type. I should have played with other input programs for the compiler to check anyway - that was my bad. I believe that "bad node type" could be detected before type checking. For example, speaking in AST terms, one could say that a binary expression can never be the left part of an assignment. I do not know whether this distinction could be part of the syntax package, or be considered a syntax error. But intuitively and practically, it seems to me like it could happen. |
To clarify - my thinking is that then the error for the example above would be something like |
@mvdan Understood - such an error message for assignments may be helpful on its own, and it that case we might not get this error here. There's a lot of information that could be extracted from the AST before type-checking; it's a bit of a balancing act as to what errors the parser should report that are not pure syntax errors (syntactically, Independent of that (error for assignments), if the code would have been Perhaps the best solution is to do all three: Look for funny looking assignments (1), and in the error message here refer to the statement used as value (2), and the possibility of a missing semicolon (3). Will play with this. |
Change https://golang.org/cl/87316 mentions this issue: |
@mvdan I opted for simply highlighting (in the error message) the fact that we have an assignment here. See pending CL. |
Change https://golang.org/cl/88336 mentions this issue: |
R=go1.11. Now that we have a syntax error test harness, we can add the proper tests for the recent parser fixes. For #20800. For #20789. For #23385. For #23434. A test for #20789 already exists in test/fixedbugs, but this is the better location for that test. But leaving the existing one where it is as well. Change-Id: I5937b9b63bafd1efab467a00344302e717976171 Reviewed-on: https://go-review.googlesource.com/88336 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What did you do?
https://play.golang.org/p/v7w9KCIbiDx
What did you expect to see?
What did you see instead?
I encountered this in a real program, where I typed
=
instead of==
. The overall boolean expression was much larger, so the error message wasn't very useful. I had to read the whole thing to manually spot where the mistake was.I think that this error should instead point at what subexpression was invalid. That is, assuming that the syntax tree resulting from the bad program above has enough information to do that, which I hope it does. /cc @griesemer
The text was updated successfully, but these errors were encountered: