Skip to content

Commit

Permalink
[gopls-release-branch.0.15] gopls/internal/cache: avoid panic when th…
Browse files Browse the repository at this point in the history
…e primary diagnostic is broken

If the primary diagnostic has invalid position information (due to a bug
in the parser or AST fix logic), gopls may panics when linking primary
and related information. Avoid this panic.

Updates golang/go#66731
Updates golang/go#66730

Change-Id: Ie2f95d158a1c93d00603a7ce4d38d8097bd8cb08
Reviewed-on: https://go-review.googlesource.com/c/tools/+/577259
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
(cherry picked from commit f41d27e)
Reviewed-on: https://go-review.googlesource.com/c/tools/+/577303
Auto-Submit: Robert Findley <rfindley@google.com>
  • Loading branch information
findleyr authored and gopherbot committed Apr 8, 2024
1 parent 4bdbdca commit dda1721
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion gopls/internal/cache/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,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},
Expand Down

0 comments on commit dda1721

Please sign in to comment.