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: crash in signature help #63804

Closed
adonovan opened this issue Oct 28, 2023 · 1 comment
Closed

x/tools/gopls: crash in signature help #63804

adonovan opened this issue Oct 28, 2023 · 1 comment
Assignees
Labels
gopls/telemetry-wins gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository.
Milestone

Comments

@adonovan
Copy link
Member

This bug.Reportf stack was was reported by telemetry:

golang.org/x/tools/gopls/internal/bug.report:35
golang.org/x/tools/gopls/internal/bug.Errorf:2
golang.org/x/tools/gopls/internal/lsp/source.SignatureHelp:72
golang.org/x/tools/gopls/internal/lsp.(*Server).signatureHelp:9
golang.org/x/tools/gopls/internal/lsp.(*Server).SignatureHelp:1
golang.org/x/tools/gopls/internal/lsp/protocol.serverDispatch:490
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.ServerHandler.func3:5
golang.org/x/tools/gopls/internal/lsp/lsprpc.(*StreamServer).ServeStream.handshaker.func4:52
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.MustReplyHandler.func1:2
golang.org/x/tools/gopls/internal/lsp/protocol.Handlers.AsyncHandler.func2.2:3

It looks like I forgot to handle the case of a conversion T(x) where T is a built-in type:

	// Get the object representing the function, if available.
	// There is no object in certain cases such as calling a function returned by
	// a function (e.g. "foo()()").
	var obj types.Object
	switch t := callExpr.Fun.(type) {
	case *ast.Ident:
		obj = pkg.GetTypesInfo().ObjectOf(t)
	case *ast.SelectorExpr:
		obj = pkg.GetTypesInfo().ObjectOf(t.Sel)
	}

	// Built-in?
	if obj != nil && !obj.Pos().IsValid() {
		// built-in function?
		if obj, ok := obj.(*types.Builtin); ok {
			return builtinSignature(ctx, snapshot, callExpr, obj.Name(), pos)
		}

		// error.Error?
		if fn, ok := obj.(*types.Func); ok && fn.Name() == "Error" {
			return &protocol.SignatureInformation{
				Label:         "Error()",
				Documentation: stringToSigInfoDocumentation("Error returns the error message.", snapshot.Options()),
			}, 0, nil
		}
		// [MISSING LOGIC for T(x) conversion here]
		return nil, 0, bug.Errorf("call to unexpected built-in %v (%T)", obj, obj)
	}
@adonovan adonovan added gopls Issues related to the Go language server, gopls. Tools This label describes issues relating to any tools in the x/tools repository. labels Oct 28, 2023
@gopherbot gopherbot added this to the Unreleased milestone Oct 28, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.15.0 Nov 2, 2023
@findleyr findleyr assigned findleyr and adonovan and unassigned findleyr Nov 2, 2023
@gopherbot
Copy link

Change https://go.dev/cl/542057 mentions this issue: gopls/internal/lsp/source: fix panic on T(x) conversion

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. Tools This label describes issues relating to any tools in the x/tools repository.
Projects
None yet
Development

No branches or pull requests

3 participants