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: Completion: failed type assertion in completer.item #71044

Closed
adonovan opened this issue Dec 27, 2024 · 6 comments
Closed

x/tools/gopls: Completion: failed type assertion in completer.item #71044

adonovan opened this issue Dec 27, 2024 · 6 comments
Assignees
Labels
gopls/completion Issues related to auto-completion in gopls. 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

#!stacks
"runtime.typeAssert" && "completion.(*completer).item:+33"

Issue created by stacks.

	if isTypeName(obj) && c.wantTypeParams() {
		// obj is a *types.TypeName, so its type must be Alias|Named.
		tparams := typesinternal.TypeParams(obj.Type().(typesinternal.NamedOrAlias))
		label += typesutil.FormatTypeParams(tparams)
		insert = label // maintain invariant above (label == insert)
	}

This stack kzwYeg was reported by telemetry:

golang.org/x/tools/gopls@v0.17.1 go1.23.4 darwin/arm64 other,vscode (5)
@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 gopls/completion Issues related to auto-completion in gopls. labels Dec 27, 2024
@adonovan
Copy link
Member Author

adonovan commented Jan 7, 2025

See amap.zip for a repro test case, courtesy of @qiulaidongfeng.

@findleyr
Copy link
Member

@qiulaidongfeng do you recall exactly what you were completing when you encountered this crash?

@findleyr findleyr modified the milestones: gopls/v0.17.2, gopls/v0.18.0 Jan 15, 2025
@findleyr
Copy link
Member

Nevermind: I can construct a simple repro based on this stack.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/643016 mentions this issue: gopls/internal/golang/completion: fix crash adding receiver type params

@qiulaidongfeng
Copy link
Member

@qiulaidongfeng do you recall exactly what you were completing when you encountered this crash?

Yes, I was writing a method declaration at the time when writing the receiver type, line 41 of amap.zip

I can reproduce it.

[Error - 08:07:57] 2025/01/16 08:07:57 imports fixes: allImportsFixes: D:\file\gofile\amap2\amap\uint64.go:41:18: expected '(', found newline (and 2 more errors)
file="D:\file\gofile\amap2\amap\uint64.go"

panic: interface conversion: *types.Basic is not typesinternal.NamedOrAlias: missing method Obj

goroutine 12912 gp=0xc00654fc00 m=0 mp=0x25a5100 [running]:
panic({0x1a03ee0?, 0xc0072fec60?})
C:/Users/26454/.go/gotip/src/runtime/panic.go:806 +0x168 fp=0xc006efc870 sp=0xc006efc7c0 pc=0xed06c8
runtime.getitab(0x1a37f60, 0x1a92ea0, 0x0)
C:/Users/26454/.go/gotip/src/runtime/iface.go:102 +0x1c5 fp=0xc006efc8b8 sp=0xc006efc870 pc=0xecde45
runtime.typeAssert(0x2566be0, 0x1a92ea0)
C:/Users/26454/.go/gotip/src/runtime/iface.go:474 +0x3f fp=0xc006efc8f8 sp=0xc006efc8b8 pc=0xe6e99f
golang.org/x/tools/gopls/internal/golang/completion.(*completer).item(, {, _}, {{0x1e6b178, 0xc00012a640}, 0x4012333333333333, {0xc00b8bc7d0, 0xe}, {0x0, 0x0}, ...})
D:/file/gofile/pkg/mod/golang.org/x/tools/gopls@v0.17.1/internal/golang/completion/format.go:65 +0x373 fp=0xc006efcd30 sp=0xc006efc8f8 pc=0x1891bd3
golang.org/x/tools/gopls/internal/golang/completion.(*completer).addCandidate(0xc00030a008, {0x1e5d028, 0xc006efed70}, 0xc006efd058)
D:/file/gofile/pkg/mod/golang.org/x/tools/gopls@v0.17.1/internal/golang/completion/deep_completion.go:294 +0x3d3 fp=0xc006efcfe0 sp=0xc006efcd30 pc=0x188f633
golang.org/x/tools/gopls/internal/golang/completion.(*completer).deepSearch(0xc00030a008, {0x1e5d028, 0xc006efed70}, 0x0?, 0xc00b8bc680?)
D:/file/gofile/pkg/mod/golang.org/x/tools/gopls@v0.17.1/internal/golang/completion/deep_completion.go:180 +0x4df fp=0xc006efd220 sp=0xc006efcfe0 pc=0x188e6ff
golang.org/x/tools/gopls/internal/golang/completion.Completion({0x1e5cff0?, 0xc0072c6c30?}, 0xc0072590e0, {0x1e5fdc0, 0xc00721fda0}, {0x0?, 0x0?}, {0x1, {0x0, 0x0}})
D:/file/gofile/pkg/mod/golang.org/x/tools/gopls@v0.17.1/internal/golang/completion/completion.go:659 +0x12fb fp=0xc006efd6f8 sp=0xc006efd220 pc=0x187cf5b
golang.org/x/tools/gopls/internal/server.(*server).Completion(0xc0000fa900, {0x1e5cff0, 0xc0072c6c30}, 0xc006efeb40)
D:/file/gofile/pkg/mod/golang.org/x/tools/gopls@v0.17.1/internal/server/completion.go:43 +0x358 fp=0xc006efd900 sp=0xc006efd6f8 pc=0x18c9518
golang.org/x/tools/gopls/internal/protocol.serverDispatch({0x1e5cff0, 0xc0070e3b90}, {0x1e7c780, 0xc0000fa900}, 0xc0072c6b40, {0x1e5d1e8, 0xc006bafac0})
D:/file/gofile/pkg/mod/golang.org/x/tools/gopls@v0.17.1/internal/protocol/tsserver.go:363 +0x2547 fp=0xc006efdbe0 sp=0xc006efd900 pc=0x126af27
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.ServerHandler.func3({0x1e5cff0, 0xc0070e3b90}, 0xc0072c6b40, {0x1e5d1e8, 0xc006bafac0})
D:/file/gofile/pkg/mod/golang.org/x/tools/gopls@v0.17.1/internal/protocol/protocol.go:160 +0x85 fp=0xc006efdc40 sp=0xc006efdbe0 pc=0x18eba65
golang.org/x/tools/gopls/internal/lsprpc.(*streamServer).ServeStream.handshaker.func4({0x1e5cff0, 0xc0070e3b90}, 0xc0072c6b40, {0x1e5d1e8, 0xc006bafac0})
D:/file/gofile/pkg/mod/golang.org/x/tools/gopls@v0.17.1/internal/lsprpc/lsprpc.go:509 +0x90b fp=0xc006efdef8 sp=0xc006efdc40 pc=0x18eb7cb
golang.org/x/tools/gopls/internal/protocol.Handlers.MustReplyHandler.func1({0x1e5cff0, 0xc0070e3b90}, 0xc0070bb4b8, {0x1e5d1e8, 0xc006bafac0})
D:/file/gofile/pkg/mod/golang.org/x/tools@v0.27.1-0.20241219162658-575221bfbda3/internal/jsonrpc2/handler.go:35 +0xc6 fp=0xc006efdf50 sp=0xc006efdef8 pc=0x125a466
golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2.2()
D:/file/gofile/pkg/mod/golang.org/x/tools@v0.27.1-0.20241219162658-575221bfbda3/internal/jsonrpc2/handler.go:104 +0x96 fp=0xc006efdfe0 sp=0xc006efdf50 pc=0x125a296
runtime.goexit({})
C:/Users/26454/.go/gotip/src/runtime/asm_amd64.s:1700 +0x1 fp=0xc006efdfe8 sp=0xc006efdfe0 pc=0xed8681
created by golang.org/x/tools/gopls/internal/protocol.Handlers.AsyncHandler.func2 in goroutine 120
D:/file/gofile/pkg/mod/golang.org/x/tools@v0.27.1-0.20241219162658-575221bfbda3/internal/jsonrpc2/handler.go:101 +0x22f

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

5 participants