Skip to content

Commit

Permalink
gopls/internal/cache: analysis: repair start/end and refine bug report
Browse files Browse the repository at this point in the history
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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
  • Loading branch information
adonovan committed Apr 5, 2024
1 parent cb3eb43 commit c7b6b8d
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions gopls/internal/cache/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -1289,11 +1289,24 @@ func (act *action) exec() (interface{}, *actionSummary, error) {
}

// debugging #64547
if start < token.Pos(tokFile.Base()) {
fileStart := token.Pos(tokFile.Base())
fileEnd := fileStart + token.Pos(tokFile.Size())
if start < fileStart {
bug.Reportf("start < start of file")
start = fileStart
}
if end > token.Pos(tokFile.Base()+tokFile.Size()+1) {
if end < start {
// This can happen if End is zero (#66683)
// or a small positive displacement from zero
// due to recursively Node.End() computation.
// This usually arises from poor parser recovery
// of an incomplete term at EOF.
bug.Reportf("end < start of file")
end = fileEnd
}
if end > fileEnd+1 {
bug.Reportf("end > end of file + 1")
end = fileEnd
}

return p.PosLocation(start, end)
Expand Down

0 comments on commit c7b6b8d

Please sign in to comment.