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/doc: confused by //line comments #5247
Labels
Milestone
Comments
Owner changed to @griesemer. |
I looked briefly into this. Boiled down example: package p //line file:2 // G doc. func G() but change the line number to file:10 and the comment is correctly dropped. It appears that the problem is that various pieces of the parser assume they can do comparisons against the raw line number returned by f.Line(pos), but they cannot: they need to compare against both the file and the line number. Or perhaps the token.File needs to expose a RawLine() int that is 1 + the actual number of \ns before that point in the input, meaning the line number ignoring //line directives, and then the parser would use that. Not going to happen for Go 1.2. Labels changed: added go1.3, removed go1.2. |
The underlying problem is that token.Positions report positions as modified via //line comments. To properly solve this, we need access to both the original (non-modified) line positions, and the modified line positions. This requires an API change (adding another position accessor), and may have complex consequences for clients of token positions if we change the semantics of the current Position accessor. For instance, commenting out go/token/position.go:272-281, which means "ignore //line comments" resolves this specific test case. Russ suggests providing another accessor, go/token.File.RawLine (which would also require go/token.File.RawPosition). gofmt would only rely on raw positions, since it formats the raw source irrespective of how that source was generated. Alternatively, one might provide go/token.File.ModifiedLine, and ModifiedPosition, which would take the role of the current Line and Position accessors, and the current Line and Position accessors would provide the raw information instead. This would make sense if most tools cared mostly about the actual position of the incoming Go source code, rather than the //line-directed source positions. There may also be a chance we can circumvent the issue by using the go/printer.SourcePos mode with gofmt (simply setting it though didn't resolve the issue - there may be other bugs). Marking Go1.3Maybe for now. Labels changed: added release-go1.3maybe, removed release-go1.3. |
Pending CL: https://golang.org/cl/84050044 Also: Filed issue #7702 for a true fix (for 1.4). Status changed to Started. |
This issue was closed by revision golang/tools@55ea531. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by santucco:
The text was updated successfully, but these errors were encountered: