-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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: incorrect comment end position with CRLF line endings #41197
Comments
/cc @griesemer per owners. |
This is a bit tricky to fix. The comment literal has '\r' stripped (from This could of course be fixed by simply not stripping the |
Change https://golang.org/cl/255657 mentions this issue: |
After jotting down the above CL, I realized that solving this bug may not be possible. We cannot change comment text to include carriage returns. That ship has sailed. The CL above instead captures more information: the position of the 'EndSlash' in the original file. On the surface, this avoids a breaking change by simply adding new information to the AST. But of course, this information is not independent: for newline separated text, we must have the invariant that What I realized is that there is already a moderate amount of code out there (some in the stdlib, some not) that implicitly relies on the invariant that Unfortunately, on first principles I don't think there's a fix out there that avoids this pitfall. We could be slightly more 'independent' by, for example, storing the number of carriage returns in the comment text, rather than the exact position of the ending slash. But that still breaks any rewrite that changes this number. So this is probably not a bug that can be fixed, and code that needs exact end positions of the comment node must recompute it using the original file, as gopls does. Unless anyone has other ideas, I'll send a CL updating the documentation for ast.Comment to make this limitation clearer, and close this issue as unfixable. |
Change https://golang.org/cl/270938 mentions this issue: |
Full repro case here: https://play.golang.org/p/JwZQ7Zjaypp.
go/parser produces incorrect position information for multi-line comments in files with CRLF line endings. This caused #41057 in
gopls
.The text was updated successfully, but these errors were encountered: