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: InvalidIfaceAssign wrong type for method, have H() H want H() H #53020

Closed
kaovilai opened this issue May 21, 2022 · 6 comments
Closed
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

@kaovilai
Copy link

gopls version

gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.8.4
    golang.org/x/tools/gopls@v0.8.4 h1:zGZsAXAb0LLws/Z+2BCWR17dkPHhIO2GYwYSSkeXX5c=
    github.com/BurntSushi/toml@v1.0.0 h1:dtDWrepsVPfW9H/4y7dDgFc2MBUSeJhlaDtK13CxFlU=
    github.com/google/go-cmp@v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o=
    github.com/sergi/go-diff@v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/exp/typeparams@v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
    golang.org/x/mod@v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
    golang.org/x/sync@v0.0.0-20210220032951-036812b2e83c h1:5KslGYwFpkhGh+Q16bwMP3cOontH8FOep7tGV86Y7SQ=
    golang.org/x/sys@v0.0.0-20220209214540-3681064d5158 h1:rm+CHSpPEEW2IsXUib1ThaHIjuBVZjxNgSKmBLFfD4c=
    golang.org/x/text@v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
    golang.org/x/tools@v0.1.11-0.20220513164230-dfee1649af67 h1:CJwk4qG1fov4WP7/DWhhb7OQVZlQKAl1rEMnDF+ceGU=
    golang.org/x/vuln@v0.0.0-20220503210553-a5481fb0c8be h1:jokAF1mfylAi1iTQx7C44B7vyXUcSEMw8eDv0PzNu8s=
    honnef.co/go/tools@v0.3.0 h1:2LdYUZ7CIxnYgskbUZfY7FPggmqnh6shBqfWa8Tn3XU=
    mvdan.cc/gofumpt@v0.3.0 h1:kTojdZo9AcEYbQYhGuLf/zszYthRdhDNDUi2JKTxas4=
    mvdan.cc/xurls/v2@v2.4.0 h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.18.2

go env

 go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tiger/Library/Caches/go-build"
GOENV="/Users/tiger/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/tiger/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/tiger/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18.2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/tiger/git/udistribution/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/62/wkysd_4n0w57ljl9ycfsd9cc0000gn/T/go-build690636367=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Open this file in VSCode
https://github.com/kaovilai/udistribution/blob/aa22efb91d74e7412c437eb618cc02f4ad46f28a/pkg/client/client_test.go after checking out the repo

What did you expect to see?

No problem reported, go test ./... run no issues.

What did you see instead?

go test ./... run no issues.

The rr variable from

gotClient.GetApp().ServeHTTP(rr, rq)

from https://github.com/kaovilai/udistribution/blob/aa22efb91d74e7412c437eb618cc02f4ad46f28a/pkg/client/client_test.go#L83
has an error coming from gopls. This is the message.

[{
	"resource": "/Users/tiger/git/udistribution/pkg/client/client_test.go",
	"owner": "_generated_diagnostic_collection_name_#5",
	"code": {
		"value": "InvalidIfaceAssign",
		"target": {
			"$mid": 1,
			"external": "https://pkg.go.dev/golang.org/x/tools/internal/typesinternal?utm_source%3Dgopls#InvalidIfaceAssign",
			"path": "/golang.org/x/tools/internal/typesinternal",
			"scheme": "https",
			"authority": "pkg.go.dev",
			"query": "utm_source=gopls",
			"fragment": "InvalidIfaceAssign"
		}
	},
	"severity": 8,
	"message": "cannot use rr (variable of type *httptest.ResponseRecorder) as http.ResponseWriter value in argument to gotClient.GetApp().ServeHTTP: *httptest.ResponseRecorder does not implement http.ResponseWriter (wrong type for method Header)\n\t\thave Header() http.Header\n\t\twant Header() http.Header",
	"source": "compiler",
	"startLineNumber": 83,
	"startColumn": 33,
	"endLineNumber": 83,
	"endColumn": 35
}]

Editor and settings

    "go.toolsManagement.autoUpdate": true,
    "go.executable.path": "/usr/local/go/bin/go",
    "go.delveConfig": {
        "dlvLoadConfig": {
            "followPointers": true,
            "maxVariableRecurse": 1,
            "maxStringLen": 64,
            "maxArrayValues": 64,
            "maxStructFields": -1
        },
        "apiVersion": 2,
        "showGlobalVariables": false,
        "debugAdapter": "legacy",
        "substitutePath": []
    },

Logs

@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 May 21, 2022
@gopherbot gopherbot added this to the Unreleased milestone May 21, 2022
@kaovilai kaovilai changed the title x/tools/gopls: InvalidIfaceAssign have Header() http.Header want Header() http.Header x/tools/gopls: InvalidIfaceAssign wrong type for method, have H() H want H() H May 21, 2022
@findleyr
Copy link
Contributor

Thank you for filing this issue. I tried and was not able to reproduce. A couple questions that may help me repro:

  • Are you using vscode's "open file" feature, or are you opening a directory? If the latter, which directory are you opening?
  • Does this repro every time for you?
  • Are you using a go.work file for this workspace?

@kaovilai
Copy link
Author

Ok I made a new dir and tried my repro steps. Did not appear to work. The same dir also no longer have the issue after reopening.. Last time I reopened the issue did not go away.

Must be some lingering state from somewhere. But I have seen the pattern of InvalidIfaceAssign wrong type for method, have H() H want H() H more than once in VSCode in different projects.

Closing for now until I can find a consistent reproducible steps.

@findleyr
Copy link
Contributor

I'd love to understand how your gopls got into this state.

I could see this happening if you'd updated your go command (say to 1.18.2), and we somehow didn't propagate invalidations of standard library types. Is it possible that this was from an old session that was started before you updated Go?

@kaovilai
Copy link
Author

Could be. Don't have any solid proof. :/

@kaovilai

This comment was marked as resolved.

@kaovilai

This comment was marked as resolved.

@golang golang locked and limited conversation to collaborators May 24, 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

3 participants