Skip to content

Commit 1f7dbdf

Browse files
adonovangopherbot
authored andcommitted
gopls/internal/cache: add debug assertions for bug report
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]>
1 parent 4d4e802 commit 1f7dbdf

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

gopls/internal/cache/check.go

+31-1
Original file line numberDiff line numberDiff line change
@@ -1823,6 +1823,12 @@ func typeErrorsToDiagnostics(pkg *syntaxPackage, errs []types.Error, linkTarget
18231823
// report.
18241824
continue
18251825
}
1826+
1827+
// Invariant: both start and end are IsValid.
1828+
if !end.IsValid() {
1829+
panic("end is invalid")
1830+
}
1831+
18261832
posn := safetoken.StartPosition(e.Fset, start)
18271833
if !posn.IsValid() {
18281834
// All valid positions produced by the type checker should described by
@@ -1848,10 +1854,34 @@ func typeErrorsToDiagnostics(pkg *syntaxPackage, errs []types.Error, linkTarget
18481854
}
18491855
continue
18501856
}
1851-
if !end.IsValid() || end == start {
1857+
1858+
// debugging #65960
1859+
//
1860+
// At this point, we know 'start' IsValid, and
1861+
// StartPosition(start) worked (with e.Fset).
1862+
//
1863+
// If the asserted condition is true, 'start'
1864+
// is also in range for pgf.Tok, which means
1865+
// the PosRange failure must be caused by 'end'.
1866+
if pgf.Tok != e.Fset.File(start) {
1867+
bug.Reportf("internal error: inconsistent token.Files for pos")
1868+
}
1869+
1870+
if end == start {
18521871
// Expand the end position to a more meaningful span.
18531872
end = analysisinternal.TypeErrorEndPos(e.Fset, pgf.Src, start)
1873+
1874+
// debugging #65960
1875+
if _, err := safetoken.Offset(pgf.Tok, end); err != nil {
1876+
bug.Reportf("TypeErrorEndPos returned invalid end: %v", err)
1877+
}
1878+
} else {
1879+
// debugging #65960
1880+
if _, err := safetoken.Offset(pgf.Tok, end); err != nil {
1881+
bug.Reportf("ReadGo116ErrorData returned invalid end: %v", err)
1882+
}
18541883
}
1884+
18551885
rng, err := pgf.Mapper.PosRange(pgf.Tok, start, end)
18561886
if err != nil {
18571887
bug.Reportf("internal error: could not compute pos to range for %v: %v", e, err)

0 commit comments

Comments
 (0)