Skip to content

Commit

Permalink
[gopls-release-branch.0.15] gopls/internal/cache: analysis: repair st…
Browse files Browse the repository at this point in the history
…art/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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
(cherry picked from commit c7b6b8d)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/577595
Auto-Submit: Alan Donovan <adonovan@google.com>
  • Loading branch information
adonovan authored and gopherbot committed Apr 9, 2024
1 parent dda1721 commit 91b4992
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 @@ -1288,11 +1288,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 91b4992

Please sign in to comment.