Skip to content

Commit

Permalink
gopls/internal/cache: add debug assertions for bug report
Browse files Browse the repository at this point in the history
Updates golang/go#65960

Change-Id: I01a416a0cf9cf8e13195c0d9405008ded1a9c53a
Reviewed-on: https://go-review.googlesource.com/c/tools/+/567416
Auto-Submit: Alan Donovan <[email protected]>
Reviewed-by: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
adonovan authored and gopherbot committed Feb 28, 2024
1 parent 4d4e802 commit 1f7dbdf
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -1823,6 +1823,12 @@ func typeErrorsToDiagnostics(pkg *syntaxPackage, errs []types.Error, linkTarget
// report.
continue
}

// Invariant: both start and end are IsValid.
if !end.IsValid() {
panic("end is invalid")
}

posn := safetoken.StartPosition(e.Fset, start)
if !posn.IsValid() {
// All valid positions produced by the type checker should described by
Expand All @@ -1848,10 +1854,34 @@ func typeErrorsToDiagnostics(pkg *syntaxPackage, errs []types.Error, linkTarget
}
continue
}
if !end.IsValid() || end == start {

// debugging #65960
//
// At this point, we know 'start' IsValid, and
// StartPosition(start) worked (with e.Fset).
//
// If the asserted condition is true, 'start'
// is also in range for pgf.Tok, which means
// the PosRange failure must be caused by 'end'.
if pgf.Tok != e.Fset.File(start) {
bug.Reportf("internal error: inconsistent token.Files for pos")
}

if end == start {
// Expand the end position to a more meaningful span.
end = analysisinternal.TypeErrorEndPos(e.Fset, pgf.Src, start)

// debugging #65960
if _, err := safetoken.Offset(pgf.Tok, end); err != nil {
bug.Reportf("TypeErrorEndPos returned invalid end: %v", err)
}
} else {
// debugging #65960
if _, err := safetoken.Offset(pgf.Tok, end); err != nil {
bug.Reportf("ReadGo116ErrorData returned invalid end: %v", err)
}
}

rng, err := pgf.Mapper.PosRange(pgf.Tok, start, end)
if err != nil {
bug.Reportf("internal error: could not compute pos to range for %v: %v", e, err)
Expand Down

0 comments on commit 1f7dbdf

Please sign in to comment.