golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
123.72k stars 17.62k forks source link

x/tools/gopls: panic after failed PosRange in xrefs.Index #67704

Open perrybenyella opened 5 months ago

perrybenyella commented 5 months ago

gopls version: v0.15.3/go1.22.1 gopls flags: update flags: proxy extension version: 0.41.4 environment: Visual Studio Code darwin initialization error: undefined issue timestamp: Sun, 26 May 2024 22:40:43 GMT restart history: Sun, 26 May 2024 21:36:23 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

panic: start: pos 1 is not in range [68046:88632] of file /Users/perrybenyella/Documents/GitHub/CS345/CS_345_Distributed_Systems/raft/test_test.go

goroutine 1514 [running]:
golang.org/x/tools/gopls/internal/cache/xrefs.Index.func2({0x101713c20, 0x14000e8d160})
      xrefs.go:52  0x8c
golang.org/x/tools/gopls/internal/cache/xrefs.Index.func3({0x101713c20%3F, 0x14000e8d160})
      xrefs.go:89  0x464
go/ast.inspector.Visit(0x140025b3400, {0x101713c20%3F, 0x14000e8d160%3F})
      walk.go:386  0x38
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713c20, 0x14000e8d160})
      walk.go:51  0x44
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713e50, 0x1400000f680})
      walk.go:112  0x1d94
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713e28, 0x14000d2bac0})
      walk.go:143  0x21e8
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713e00, 0x140004b3380})
      walk.go:153  0x1948
go/ast.walkExprList(...)
      walk.go:26
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713e28, 0x14000d2bb40})
      walk.go:144  0x2208
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101714760, 0x14000d40a80})
      walk.go:206  0x3254
go/ast.walkStmtList(...)
      walk.go:32
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713f40, 0x14000574210})
      walk.go:234  0x29f4
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713ea0, 0x14000574240})
      walk.go:357  0xd90
go/ast.walkDeclList(...)
      walk.go:38
go/ast.Walk({0x1017108c0%3F, 0x140025b3400%3F}, {0x101713ce8, 0x1400048ac80})
      walk.go:366  0x2e14
go/ast.Inspect(...)
      walk.go:397
golang.org/x/tools/gopls/internal/cache/xrefs.Index({0x140011712f0, 0x5, 0x140022bd600%3F}, 0x140010bf2c0, 0x140010bf320)
      xrefs.go:57  0x130
golang.org/x/tools/gopls/internal/cache.(*syntaxPackage).xrefs.func1()
      pkg.go:72  0x38
sync.(*Once).doSlow(0x14000582d08%3F, 0x14000583388%3F)
      once.go:74  0x100
sync.(*Once).Do(...)
      once.go:65
golang.org/x/tools/gopls/internal/cache.(*syntaxPackage).xrefs(0x140002bc2d0)
      pkg.go:71  0x50
golang.org/x/tools/gopls/internal/cache.storePackageResults({0x1017189e8, 0x14001c460f0}, 0x14001164d80, 0x140011e2420)
      check.go:582  0x80
created by golang.org/x/tools/gopls/internal/cache.(*typeCheckBatch).handleSyntaxPackage in goroutine 1420
      check.go:570  0x5d0
gopls stats -anon { "DirStats": { "Files": 440, "TestdataFiles": 0, "GoFiles": 44, "ModFiles": 2, "Dirs": 198 }, "GOARCH": "arm64", "GOOS": "darwin", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.22.1", "GoplsVersion": "v0.15.3", "InitialWorkspaceLoadDuration": "88.230458ms", "MemStats": { "HeapAlloc": 2537088, "HeapInUse": 4964352, "TotalAlloc": 11719808 }, "WorkspaceStats": { "Files": { "Total": 0, "Largest": 0, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.22.1", "AllPackages": { "Packages": 0, "LargestPackage": 0, "CompiledGoFiles": 0, "Modules": 0 }, "WorkspacePackages": { "Packages": 0, "LargestPackage": 0, "CompiledGoFiles": 0, "Modules": 0 }, "Diagnostics": 0 } ] } }
OPTIONAL: If you would like to share more information, you can attach your complete gopls logs. NOTE: THESE MAY CONTAIN SENSITIVE INFORMATION ABOUT YOUR CODEBASE. DO NOT SHARE LOGS IF YOU ARE WORKING IN A PRIVATE REPOSITORY.
findleyr commented 4 months ago

CC @adonovan this is a new one.

Transferring to the Go issue tracker.

adonovan commented 4 months ago

This is the offending line, complete with "can't fail" comment. ;-)

        nodeRange := func(n ast.Node) protocol.Range {
            rng, err := pgf.PosRange(n.Pos(), n.End())
            if err != nil {
                panic(err) // can't fail
            }
            return rng
        }

Interpreting the stack, the offending Node is the Sel identifier in a call expression x.Sel(...). I don't know how it got a bogus start pos of 1.

adonovan commented 4 months ago

Hi @perrybenyella, do you remember how you triggered this crash while working in test_test.go? If you're able to reproduce it, that would be a great help for us trying to fix it. Thanks!

findleyr commented 4 months ago

Bumping to the next milestone as this code has not changed recently, and this is our first report of this crash.

Hopefully we can get a reproducer.

perrybenyella commented 4 months ago

I am not exactly sure, but I was working on a project on vscode using the live share extension with a couple of other collaborators. Then we made edits to the files (test_test.go was one of these files), and for some reason, we weren't able to save the changes we made to the files while working. Because of that, I had to restart my vs code each tim,\e it happened. This kind of happend a few times. It also seemed to be an issue that only my computer was affected by because the other collaborators did not experience it when they used their own live share links.

findleyr commented 3 days ago

Absent a reproducer, I'm afraid we're unlikely to be able to fix this. Moving to the backlog.