Repository: go
Issue: x/tools/gopls: panic after failed PosRange in xrefs.Index
Labels: gopls,Tools

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.

<ANSWER HERE>

<pre>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
</pre>

<details><summary>gopls stats -anon</summary>
{
  "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
      }
    ]
  }
}

</details>

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.

<OPTIONAL: ATTACH LOGS HERE>