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: spurious unused errors for used imports in expected function calls e.g defers and go #23586
Comments
It is not unnecessary. It is by design - https://golang.org/doc/faq#unused_variables_and_imports.
|
I think OP's point is that fmt is used in the program, even if it's in a malformed go/defer expression. Smaller reproducer:
Perhaps this is by design. I don't know how far are invalid expressions typechecked. /cc @griesemer @mdempsky |
I agree that the compiler could do better in this case; there's really just one error here (the deferred function must be invoked). The compiler is also not consistent. For instance, in this case
we have the opposite situation; |
@griesemer I think the case in your comment is acceptable. |
The root cause for the current behavior is that the check that the In this case it may make sense to move that test to later (out of the parser) for a couple of reasons: 1) it is quite common to make the mistake of forgetting to call the deferred function; and 2) the syntax actually doesn't state that the expression must be a function call, that restriction in made in prose. As a general (but not hard and fast) rule for the parser, syntactic restrictions that are in prose are handled outside the parser. |
Change https://golang.org/cl/94155 mentions this issue: |
Change https://golang.org/cl/94156 mentions this issue: |
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd6
Does this issue reproduce with the latest release?
yes
What did you do?
What did you expect to see?
What did you see instead?
The text was updated successfully, but these errors were encountered: