Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
findleyr opened this issue Oct 17, 2022 · 2 comments
Assignees
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@findleyr
Copy link
Contributor

findleyr commented Oct 17, 2022

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

@findleyr findleyr added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 17, 2022
@findleyr findleyr added this to the gopls/v0.10.0 milestone Oct 17, 2022
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Oct 17, 2022
@findleyr findleyr self-assigned this Oct 17, 2022
@findleyr
Copy link
Contributor Author

Bisected to https://go.dev/cl/425356, which makes sense: we stopped recovering this panic outside of analysis.

That change included handling for invalid end positions in diagnostics, but not related information. Corresponding fix for related information incoming.

@gopherbot
Copy link

Change https://go.dev/cl/443337 mentions this issue: gopls/internal/lsp: tolerate missing end position in RelatedInformation

@golang golang locked and limited conversation to collaborators Oct 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge gopls Issues related to the Go language server, gopls. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

2 participants