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: misleading quick fix (gopls.apply_fix) for undefined type constraint #50935

Closed
hyangah opened this issue Jan 31, 2022 · 1 comment
Labels
FrozenDueToAge 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

@hyangah
Copy link
Contributor

hyangah commented Jan 31, 2022

gopls version

go version -m ~/go/bin/gopls
/Users/hakim/go/bin/gopls: go1.18beta2
        path    golang.org/x/tools/gopls
        mod     golang.org/x/tools/gopls        v0.7.5  h1:8Az52YwcFXTWPvrRomns1C0N+zlgTyyPKWvRazO9GG8=
        ...

go env

go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hakim/Library/Caches/go-build"
GOENV="/Users/hakim/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/hakim/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/hakim/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/hakim/sdk/go1.18beta2"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/hakim/sdk/go1.18beta2/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18beta2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/hakim/ww/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/bw/6r6k9d113sv1_vvzk_1kfxbm001py5/T/go-build144163246=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Copy&paste the following code (missing declaration for C)

package p

func F[T C](m T) T {
	return m
}

What did you see "UNEXPECTEDLY"?

Quick Fix for this error.

Screen Shot 2022-01-31 at 4 44 52 PM

And, then this action fails with error
"Command 'gopls.apply_fix' failed: Error."

Editor and settings

    "gopls": {
        "ui.semanticTokens": true,
        "ui.completion.experimentalPostfixCompletions": true,        
    },

Logs


[Trace - 16:46:17.654 PM] Sending request 'textDocument/codeAction - (68)'.
Params: {"textDocument":{"uri":"file:///Users/hakim/ww/main.go"},"range":{"start":{"line":6,"character":9},"end":{"line":6,"character":10}},"context":{"diagnostics":[{"range":{"start":{"line":6,"character":9},"end":{"line":6,"character":10}},"message":"undeclared name: C","code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source%3Dgopls#UndeclaredName"},"severity":1,"source":"compiler"}],"only":["quickfix"]}}


[Trace - 16:46:17.655 PM] Received response 'textDocument/codeAction - (68)' in 0ms.
Result: [{"title":"undeclared name: C","kind":"quickfix","diagnostics":[{"range":{"start":{"line":6,"character":9},"end":{"line":6,"character":10}},"severity":1,"code":"UndeclaredName","codeDescription":{"href":"https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source%3Dgopls#UndeclaredName"},"source":"compiler","message":"undeclared name: C"}],"edit":{},"command":{"title":"undeclared name: C","command":"gopls.apply_fix","arguments":[{"Fix":"undeclared_name","URI":"file:///Users/hakim/ww/main.go","Range":{"start":{"line":6,"character":9},"end":{"line":6,"character":10}}}]}}]
...
[Trace - 16:46:53.071 PM] Sending request 'workspace/executeCommand - (80)'.
Params: {"command":"gopls.apply_fix","arguments":[{"Fix":"undeclared_name","URI":"file:///Users/hakim/ww/main.go","Range":{"start":{"line":6,"character":9},"end":{"line":6,"character":10}}}]}


[Error - Received] 16:46:53.072 PM #80 


[Error - 4:46:53 PM] Request workspace/executeCommand failed.
  Message: 
  Code: 0 
@gopherbot gopherbot added Tools This label describes issues relating to any tools in the x/tools repository. gopls Issues related to the Go language server, gopls. labels Jan 31, 2022
@gopherbot gopherbot added this to the Unreleased milestone Jan 31, 2022
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.8.0 Jan 31, 2022
@gopherbot
Copy link

Change https://go.dev/cl/384117 mentions this issue: internal/lsp/analysis/undeclaredname: suppress impossible quick fixes

@rsc rsc unassigned heschi Jun 22, 2022
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge 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

4 participants