-
Notifications
You must be signed in to change notification settings - Fork 26
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
Track Position rather than Offset #12
Conversation
This still doesn't quite do the right thing in the presence of cgo (mapping back to the original source location is somewhat broken). |
@mdempsky any other outstanding issues here? |
line := lineForOffset(buf, pos.Offset) | ||
fmt.Printf("%s\n", line) | ||
fmt.Printf("%s^\n", rub(line[:pos.Column-1])) | ||
line := lineForPos(pos) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems unfortunate to need to re-read the source file for each warning message. What was wrong with the previous method of slurping it into memory?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, it was being done even when the file wasn't needed because flagV
wasn't provided. Made this better, though.
I think I'm still confused how the Position change fixes anything. Like I said, token.Position is a superset of Offset. Do you have a test case that shows your change improves behavior? |
@mdempsky yes, if you run master against cockroachdb as described in #11, you will get a panic. After this PR, there is no panic. The reason is that there is no longer a call to file.Pos (8761692#diff-d45c7d690c87bd02c6ddd98b0dbd510fL120) which takes an offset and returns a Position (but does so incorrectly in the presence of cgo). |
Ohh, okay. I understand the issue now, thanks. |
Hm, does |
Arg, this is even subtler actually. We can only rely on line numbers being correct for cgo-processed files. The column numbers may be wrong if cgo rewrite any expressions earlier in the same line. |
I'm not sure what you're getting at, @mdempsky. Is there any reason not to merge this PR? we're currently using my fork in cockroachdb, and I'd like to resume using yours. |
So I'm getting at two things:
I expect the column number for the redundant My hesitation is that it seems to not fully solve the cgo case, and I'm looking to see if there's a better solution. |
|
I'm glad you're looking for a better solution. In the meantime, this fixes a panic, and slightly reduces the burden on me to keep rolling the boulder up the hill. What's the downside to accepting this patch? |
Thanks for testing. I just haven't finished reviewing the code yet, so I don't know yet what the downsides are, if any. I'm okay with the first commit now. The second cleanup commit makes a lot of changes that I don't understand and that don't seem related to each other, and so I'm currently still trying to understand them. I'd prefer if you sent those as a separate PR and preferably as multiple commits or at least a commit message explaining the individual changes. |
Removed the second commit, will send as a separate PR after this is merged. |
Thanks! |
Fixes #3.