gopls/internal/lsp/cache: add additional debug assertions during parsing
To narrow down the concerning issue golang/go#59080, add additional
early debug assertions to help narrow down a root cause.
For golang/go#59080
Change-Id: Ib18c2e7328eaf059c908afc6260f3212f685573c
Reviewed-on: https://go-review.googlesource.com/c/tools/+/477275
Reviewed-by: Alan Donovan <adonovan@google.com>
gopls-CI: kokoro <noreply+kokoro@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/gopls/internal/lsp/cache/parse_cache.go b/gopls/internal/lsp/cache/parse_cache.go
index 3511b75..231ede3 100644
--- a/gopls/internal/lsp/cache/parse_cache.go
+++ b/gopls/internal/lsp/cache/parse_cache.go
@@ -7,6 +7,7 @@
import (
"container/heap"
"context"
+ "fmt"
"go/parser"
"go/token"
"math/bits"
@@ -295,6 +296,22 @@
}
tokeninternal.AddExistingFiles(fset, tokenFiles)
+ const debugIssue59080 = true
+ if debugIssue59080 {
+ for _, f := range tokenFiles {
+ pos := token.Pos(f.Base())
+ f2 := fset.File(pos)
+ if f2 != f {
+ panic(fmt.Sprintf("internal error: File(%d (start)) = %v, not %v", pos, f2, f))
+ }
+ pos = token.Pos(f.Base() + f.Size())
+ f2 = fset.File(pos)
+ if f2 != f {
+ panic(fmt.Sprintf("internal error: File(%d (end)) = %v, not %v", pos, f2, f))
+ }
+ }
+ }
+
return pgfs, firstErr
}