-
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
go/parser: line numbers of comments get reset after the package statement #30761
Comments
This is working as expected. The line numbers don't get reset by the package statement; they get set by the line comment preceding it. If you make that comment not a line comment it will not "reset" the line numbers. If you want the unmodified, actual source file line numbers, irrespective of line comments, use |
If that is expected, then it certainly should be documented. It is very surprising that a block comment doesn't do anything, but a line comment sets the line numbers. And also, if I move the line comment below the package statement, everything works fine. Is there any documentation regarding this peculiar behavior between a line comment and the EDIT: The documentation for
It does not say that the position-altering happens only if it is above the package statement. Don't we need this clarification or am I misunderstanding something ? |
This is documented here. It works for line and block comments, as long as they start with Again, this has absolutely nothing to do with package clauses. This is just a mechanism of If you move the respective line comment below the package clause, you're simply renumbering the lines after that comment. This example may work "fine", others may not. |
Sorry that's right. I somehow missed that it's a |
What version of Go are you using (
go version
)?What did you do?
Consider this code -
What did you expect to see?
I expect the line numbers to be counted from the first line of the file. But they aren't. They get reset after the package statement.
What did you see instead?
Found while working on https://go-review.googlesource.com/c/go/+/162337/.
Filing this at the request of @griesemer
The text was updated successfully, but these errors were encountered: