Skip to content

Commit c7b6b8d

Browse files
committed
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 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]>
1 parent cb3eb43 commit c7b6b8d

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
@@ -1289,11 +1289,24 @@ func (act *action) exec() (interface{}, *actionSummary, error) {
12891289
}
12901290

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

12991312
return p.PosLocation(start, end)

0 commit comments

Comments
 (0)