golang / go

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

x/tools/gopls: InlayHint: nil panic due to ast.CallExpr.Fun with no type #67142

Closed hyangah closed 2 weeks ago

hyangah commented 2 weeks ago

gopls version: (devel)/go1.22.2 74c9cfe4d22faa696baabeea02df6493b15e8c79 (dev version built today) gopls flags: -rpc.trace update flags: proxy extension version: 0.41.4 environment: Visual Studio Code darwin initialization error: undefined issue timestamp: Thu, 02 May 2024 16:39:32 GMT restart history: Thu, 02 May 2024 16:39:28 GMT: activation (enabled: true)

ATTENTION: PLEASE PROVIDE THE DETAILS REQUESTED BELOW.

Describe what you observed.

Opened the folder with the following files. (local go version: 1.21.9, gopls built with go1.22.2)

--- go.mod ---
module w

go 1.21.9

--- main.go ---
package main

func main() {
    _ = rand.Float64()
}
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0xf482982]

goroutine 110 [running]:
golang.org/x/tools/internal/typeparams.CoreType({0x0%3F, 0x0%3F})
      coretype.go:18  0x22
golang.org/x/tools/gopls/internal/golang.parameterNames({0xfec8748%3F, 0xc0000562c0}, 0xc0002f0f00, 0xc0002f0ea0, 0xc1850e510a723990%3F, 0x2219fe36%3F)
      inlay_hint.go:142  0x6a
golang.org/x/tools/gopls/internal/golang.InlayHint.func1({0xfec8748, 0xc0000562c0})
      inlay_hint.go:130  0x152
go/ast.inspector.Visit(0xc000190a50, {0xfec8748%3F, 0xc0000562c0%3F})
      walk.go:386  0x2b
go/ast.Walk({0xfec4fc0%3F, 0xc000190a50%3F}, {0xfec8748, 0xc0000562c0})
      walk.go:51  0x4c
go/ast.walkExprList(...)
      walk.go:26
go/ast.Walk({0xfec4fc0%3F, 0xc000190a50%3F}, {0xfec89f0, 0xc000056300})
      walk.go:217  0x3077
go/ast.walkStmtList(...)
      walk.go:32
go/ast.Walk({0xfec4fc0%3F, 0xc000190a50%3F}, {0xfec8608, 0xc000307ef0})
      walk.go:234  0x31b7
go/ast.Walk({0xfec4fc0%3F, 0xc000190a50%3F}, {0xfec8450, 0xc000307f20})
      walk.go:357  0xfa5
go/ast.walkDeclList(...)
      walk.go:38
go/ast.Walk({0xfec4fc0%3F, 0xc000190a50%3F}, {0xfec8388, 0xc0005094a0})
      walk.go:366  0x36c5
go/ast.Inspect(...)
      walk.go:397
golang.org/x/tools/gopls/internal/golang.InlayHint({0xfecd208%3F, 0xc00067c3c0%3F}, 0xc0005407e0, {0xfecff20, 0xc0007804e0}, {{0x16%3F, 0x0%3F}, {0x4dc028%3F, 0xc0%3F}})
      inlay_hint.go:124  0x598
golang.org/x/tools/gopls/internal/server.(*server).InlayHint(0xc000212780, {0xfecd240, 0xc000406500}, 0xc00067c0f0)
      inlay_hint.go:32  0x337
golang.org/x/tools/gopls/internal/protocol.serverDispatch({0xfecd240, 0xc000406500}, {0xfee7540, 0xc000212780}, 0xc00067c0c0, {0xfecd400, 0xc000402340})
      tsserver.go:453  0x1efa
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3({0xfecd240, 0xc000406500}, 0xc00067c0c0, {0xfecd400, 0xc000402340})
      protocol.go:160  0x85
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4({0xfecd240, 0xc000406500}, 0xc00067c0c0, {0xfecd400, 0xc000402340})
      lsprpc.go:509  0x923
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1({0xfecd240, 0xc000406500}, 0xc0001a6870, {0xfecd400, 0xc000402340})
      handler.go:35  0xc6
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2()
      handler.go:103  0x96
created by golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2 in goroutine 120
      handler.go:100  0x1c5
gopls stats -anon { "DirStats": { "Files": 2, "TestdataFiles": 0, "GoFiles": 1, "ModFiles": 1, "Dirs": 1 }, "GOARCH": "amd64", "GOOS": "darwin", "GOPACKAGESDRIVER": "", "GOPLSCACHE": "", "GoVersion": "go1.22.2", "GoplsVersion": "(devel)", "InitialWorkspaceLoadDuration": "272.497863ms", "MemStats": { "HeapAlloc": 2338064, "HeapInUse": 4390912, "TotalAlloc": 6797184 }, "WorkspaceStats": { "Files": { "Total": 2, "Largest": 51, "Errs": 0 }, "Views": [ { "GoCommandVersion": "go1.21.9", "AllPackages": { "Packages": 1, "LargestPackage": 1, "CompiledGoFiles": 1, "Modules": 1 }, "WorkspacePackages": { "Packages": 1, "LargestPackage": 1, "CompiledGoFiles": 1, "Modules": 1 }, "Diagnostics": 1 } ] } }

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.

hyangah commented 2 weeks ago

Obviously I use inlay hints.

    "go.inlayHints.assignVariableTypes": true,
    "go.inlayHints.compositeLiteralFields": true,
    "go.inlayHints.compositeLiteralTypes": true,
    "go.inlayHints.constantValues": true,
    "go.inlayHints.functionTypeParameters": true,
    "go.inlayHints.parameterNames": true,
    "go.inlayHints.rangeVariableTypes": true,
findleyr commented 2 weeks ago

CC @timothy-king @adonovan

adonovan commented 2 weeks ago

Thanks for the very helpful report with minimized test case.

gopherbot commented 2 weeks ago

Change https://go.dev/cl/582957 mentions this issue: gopls/internal/golang: fix nil panic in InlayHint