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: cgocall analyzer: "token.Pos not within package" bug (reported by telemetry) #66911

Open
adonovan opened this issue Apr 18, 2024 · 3 comments
Assignees
Labels
gopls/telemetry-wins 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

@adonovan
Copy link
Member

adonovan commented Apr 18, 2024

This stack E4ACQw was reported by telemetry:

cache.(*action).exec.func2:+37 is:

		return protocol.Location{}, errorf("token.Pos not within package")
gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Errorf:+2
golang.org/x/tools/gopls/internal/cache.(*action).exec.func2:+37
golang.org/x/tools/gopls/internal/cache.toGobDiagnostic:+32
golang.org/x/tools/gopls/internal/cache.(*action).exec.func3:+1
golang.org/x/tools/go/analysis.(*Pass).Reportf:+2
golang.org/x/tools/go/analysis/passes/cgocall.checkCgo.func1:+28
go/ast.inspector.Visit:+1
go/ast.Walk:+1
go/ast.Walk:+173
go/ast.walkStmtList:=32
go/ast.Walk:+184
go/ast.Walk:+245
go/ast.walkStmtList:=32
go/ast.Walk:+184
go/ast.Walk:+307
golang.org/x/tools/gopls@v0.15.3 go1.22.0 windows/amd64 neovim,vscode (2)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

Dups: 4azcCQ

@adonovan adonovan added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. gopls/telemetry-wins labels Apr 18, 2024
@gopherbot gopherbot added this to the Unreleased milestone Apr 18, 2024
@adonovan adonovan changed the title x/tools/gopls: bug reported by telemetry x/tools/gopls: "token.Pos not within package" bug (reported by telemetry) Apr 18, 2024
@adonovan adonovan modified the milestones: Unreleased, gopls/v0.16.0 Apr 18, 2024
@adonovan adonovan changed the title x/tools/gopls: "token.Pos not within package" bug (reported by telemetry) x/tools/gopls: cgocall analyzer: "token.Pos not within package" bug (reported by telemetry) Apr 18, 2024
@adonovan
Copy link
Member Author

No wonder cgocall shows up in so many of our gopls analyzer bug reports: it runs its own parsing and type checking steps (see https://go-review.googlesource.com/c/147317), so of course we won't find its token.Pos values within the analysis package's known Pos ranges!

I'm not yet sure what the fix is, but at least now we have a theory for how to fix this issue and #64547, our most prolific generator of field reports.

@adonovan adonovan self-assigned this Apr 22, 2024
@gopherbot
Copy link

Change https://go.dev/cl/580836 mentions this issue: gopls/internal/cache: fix bug.Report converting Diagnostic positions

@adonovan
Copy link
Member Author

adonovan commented May 2, 2024

This stack 4azcCQ was reported by telemetry:

gopls/bug
golang.org/x/tools/gopls/internal/util/bug.report:+35
golang.org/x/tools/gopls/internal/util/bug.Errorf:+2
golang.org/x/tools/gopls/internal/cache.(*action).exec.func2:+37
golang.org/x/tools/gopls/internal/cache.toGobDiagnostic:+32
golang.org/x/tools/gopls/internal/cache.(*action).exec.func3:+1
golang.org/x/tools/go/analysis.(*Pass).Reportf:+2
golang.org/x/tools/go/analysis/passes/cgocall.checkCgo.func1:+28
go/ast.inspector.Visit:+1
go/ast.Walk:+1
go/ast.walkExprList:=26
go/ast.Walk:+167
go/ast.walkStmtList:=32
go/ast.Walk:+184
go/ast.Walk:+307
go/ast.walkDeclList:=38
go/ast.Walk:+316
golang.org/x/tools/gopls@v0.15.3 go1.22.0 windows/amd64 neovim,vscode (1)

Issue created by golang.org/x/tools/gopls/internal/telemetry/cmd/stacks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls/telemetry-wins 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