cmd/cover: use Scanner.End for token end positions

Now that go/scanner has an End method (accepted in #74958), the
range-building code can use it directly instead of estimating a
token's end position from pos+len(lit). The estimate was inaccurate
for raw string literals, whose lit value has carriage returns
stripped; Scanner.End reflects the true source offset.

Updates #74958.

Change-Id: I573bd039585d699cc1aeb325b749c422c874a097
Reviewed-on: https://go-review.googlesource.com/c/go/+/802144
Reviewed-by: Mark Freeman <markfreeman@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: golang-scoped@luci-project-accounts.iam.gserviceaccount.com <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Ilya Torbin 2026-07-19 16:05:31 +03:00 committed by Gopher Robot
parent 543ead71a8
commit 80a6dffae3

View File

@ -332,8 +332,7 @@ func (f *File) codeRanges(start, end token.Pos) []Range {
endLine := startLine
if tok == token.STRING {
// Only string literals can span multiple lines.
// TODO(adonovan): simplify when https://go.dev/issue/74958 is resolved.
endLine = scanFile.PositionFor(pos+token.Pos(len(lit)), false).Line
endLine = scanFile.PositionFor(s.End(), false).Line
}
if prevEndLine == 0 {