diff --git a/gopls/internal/cache/check.go b/gopls/internal/cache/check.go index dee4eec47e5..2978d14b46e 100644 --- a/gopls/internal/cache/check.go +++ b/gopls/internal/cache/check.go @@ -1968,7 +1968,10 @@ func typeErrorsToDiagnostics(pkg *syntaxPackage, errs []types.Error, linkTarget // This is because go/types assumes that errors are read top-down, such as // in the cycle error "A refers to...". The structure of the secondary // error set likely only makes sense for the primary error. - if i > 0 { + // + // NOTE: len(diags) == 0 if the primary diagnostic has invalid positions. + // See also golang/go#66731. + if i > 0 && len(diags) > 0 { primary := diags[0] primary.Related = append(primary.Related, protocol.DiagnosticRelatedInformation{ Location: protocol.Location{URI: diag.URI, Range: diag.Range},