-
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: wrong line offset for "cannot use ... in argument" error #22167
Comments
@mdempsky Can you look into this and see if there's an easy fix? |
This issue is because we reuse the same ONAME Node to represent both the declaration of the name as well as uses, so we lose position information for their use sites. We do have the position information in the package syntax AST representation, but we lose it once we convert to the Node AST representation. There are a handful of special cases (chiefly composite literals and expressions used as statements) where we insert OPAREN nodes just for the purpose of preserving position information when we want to be able to emit errors for identifier use. We could potentially expand that to more cases (e.g., function call arguments). At the extreme end, I experimented previously with always adding OPAREN nodes, which should address the entire class of problem: https://go-review.googlesource.com/c/go/+/38735 However, it had a significant performance impact on some packages, so I abandoned pursuing that solution. |
@mdempsky Thanks for checking. No matter the solution, it does appear this is too late for 1.10. I'm going to bump it and mark as "early in cycle". |
Nor urgent. Bumping down the road. |
Change https://golang.org/cl/147379 mentions this issue: |
The error messages are now (Go 1.18) coming from |
I'm enjoying having the offset-within-the-line information printed in the compiler errors, because my editor is set up to jump to the exact position being printed, which is really very nice.
But I found an example where the offset seems to be wrong:
Every argument to f in the two return statements is wrong: f takes ints and they're all strings.
While the offsets printed for the literal strings are correct, the offsets for the variable s are not. On line 8, the error about s reuses the position of the literal "hello". On line 9, the error about s seems to use the position of the opening parenthesis on the call.
In a real program I noticed this as:
The arguments - both variables of different types - had been swapped and yet the position reported was the same for both. In this case the errors reported the initial parenthesis twice instead of the beginning of each bad argument.
/cc @griesemer @mdempsky
The text was updated successfully, but these errors were encountered: