Skip to content

Commit 91b4992

Browse files
adonovangopherbot
authored andcommitted
[gopls-release-branch.0.15] gopls/internal/cache: analysis: repair start/end and refine bug report
Poor parser error recovery may cause Node.End to be zero, or a small positive displacement from zero due to recursive Node.End computation (#66683). This change further refines the bug.Reports for such problems, and additionally repairs the values heuristically to avoid downstream bug.Reports after toGobDiagnostics (#64547). Updates golang/go#66683 Updates golang/go#64547 Updates golang/go#66730 Change-Id: I7c795622ec6b63574978d2953c82036fcc4425af Reviewed-on: https://go-review.googlesource.com/c/tools/+/576655 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]> (cherry picked from commit c7b6b8d) Reviewed-on: https://go-review.googlesource.com/c/tools/+/577595 Auto-Submit: Alan Donovan <[email protected]>
1 parent dda1721 commit 91b4992

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

gopls/internal/cache/analysis.go

+15-2
Original file line numberDiff line numberDiff line change
@@ -1288,11 +1288,24 @@ func (act *action) exec() (interface{}, *actionSummary, error) {
12881288
}
12891289

12901290
// debugging #64547
1291-
if start < token.Pos(tokFile.Base()) {
1291+
fileStart := token.Pos(tokFile.Base())
1292+
fileEnd := fileStart + token.Pos(tokFile.Size())
1293+
if start < fileStart {
12921294
bug.Reportf("start < start of file")
1295+
start = fileStart
12931296
}
1294-
if end > token.Pos(tokFile.Base()+tokFile.Size()+1) {
1297+
if end < start {
1298+
// This can happen if End is zero (#66683)
1299+
// or a small positive displacement from zero
1300+
// due to recursively Node.End() computation.
1301+
// This usually arises from poor parser recovery
1302+
// of an incomplete term at EOF.
1303+
bug.Reportf("end < start of file")
1304+
end = fileEnd
1305+
}
1306+
if end > fileEnd+1 {
12951307
bug.Reportf("end > end of file + 1")
1308+
end = fileEnd
12961309
}
12971310

12981311
return p.PosLocation(start, end)

0 commit comments

Comments
 (0)