Skip to content

x/tools/gopls: crash with invalid end token.Pos for analyzers with related information #56270

@findleyr

Description

@findleyr

This crash is not yet released, but exists in gopls@v0.10.0-pre.1. Possibly related to some of the recent cleanup of position representation, we get the following panic when staticcheck is enabled. Repro: enable "staticcheck" and open x/tools/gopls/internal/lsp/source:

panic: invalid end token.Pos

goroutine 12855 [running]:
golang.org/x/tools/gopls/internal/span.NewRange(...)
        /home/rfindley/src/tools/gopls/internal/span/token.go:36
golang.org/x/tools/gopls/internal/lsp/cache.relatedInformation(0xc003461a40?, 0xc019eba5f0?, 0xc01c7efce0)
        /home/rfindley/src/tools/gopls/internal/lsp/cache/errors.go:337 +0x4f4
golang.org/x/tools/gopls/internal/lsp/cache.analysisDiagnosticDiagnostics(0xc003461a40, 0xc01c7efbb0?, 0xc00042cdd0, 0xc01c7efce0)
        /home/rfindley/src/tools/gopls/internal/lsp/cache/errors.go:241 +0x7f5
golang.org/x/tools/gopls/internal/lsp/cache.actionImpl({0x1112178, 0xc00d111600}, 0xc003461a40, {0xc0034399c0, 0x3, 0x49b2f4?}, 0xc00042cdd0, 0xc010bfa000)
        /home/rfindley/src/tools/gopls/internal/lsp/cache/analysis.go:414 +0xe9c
golang.org/x/tools/gopls/internal/lsp/cache.(*snapshot).actionHandle.func1({0x1112178?, 0xc00d111600?}, {0xe90de0?, 0xc003461a40?})
        /home/rfindley/src/tools/gopls/internal/lsp/cache/analysis.go:166 +0x5a
golang.org/x/tools/internal/memoize.(*Promise).run.func2.1()
        /home/rfindley/src/tools/internal/memoize/memoize.go:187 +0xa9
runtime/trace.WithRegion({0x1112178?, 0xc00d111600?}, {0xc00cf77ef0, 0x21}, 0xc006a0ef90)
        /home/rfindley/src/go/src/runtime/trace/annotation.go:141 +0xe3
golang.org/x/tools/internal/memoize.(*Promise).run.func2()
        /home/rfindley/src/tools/internal/memoize/memoize.go:180 +0x145
created by golang.org/x/tools/internal/memoize.(*Promise).run
        /home/rfindley/src/tools/internal/memoize/memoize.go:179 +0x1ea

Note that this is almost certainly not related to staticcheck itself. At first glance, my guess is that the distinguishing feature is the presence of related information.

Thanks @muirdm for the report (via slack).

CC @adonovan

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.goplsIssues related to the Go language server, gopls.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions