You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for finding this, but let's leave this code alone, for the following reasons:
As is, the lines 83-86 match the lines 62-65 (as they should); and line 81 could probably be the same as line 61. The code could probably be restructered so that this code section appears only once (by modifying the if on line 60). If the AddLine on line 85 is removed, this will be harder to see. In other words, the symmetry here helps understanding.
The AddLine on line 85 is called once per file at most (unless one calls next() repeatedly at EOF). This has virtually zero impact on anything.
I believe your analysis is correct, but there's always a chance that one overlooks something. This code has been running fine for a decade - let's not fiddle with it, especially since there's no bug here nor is there a performance benefit.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I was reading Go source code. The
AddLine
call here seems to be a noop:go/src/go/scanner/scanner.go
Lines 82 to 86 in c9888bd
This is because we effectively pass file size as offset and
AddLine
implementation ignores the call ifoffset >= size
:go/src/go/token/position.go
Lines 135 to 137 in c9888bd
Note that we have a guarantee that
File.size == len(src)
:go/src/go/scanner/scanner.go
Lines 125 to 127 in c9888bd
I removed that line locally and the
src/all.bash
tests still pass. Happy to send a PR to remove that line, if you are OK with this.cc @griesemer
The text was updated successfully, but these errors were encountered: