Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
go/parser: line numbers of comments get reset after the package statement #30761
What version of Go are you using (
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.