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 gives wrong lambda suggestion for pointer receivers of a generic type #61189

Closed
lixin9311 opened this issue Jul 6, 2023 · 2 comments
Assignees
Labels
FrozenDueToAge gopls/completion Issues related to auto-completion in gopls. gopls/generics Issues related to gopls' support for generics 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

@lixin9311
Copy link

gopls version

$ gopls -v version
Build info
----------
golang.org/x/tools/gopls v0.12.4
    golang.org/x/tools/[email protected] h1:nce5etAamR46d9oNGxop1aRK5rDQ0NqcY/SHIcyfEKY=
    github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak=
    github.com/google/[email protected] h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
    github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
    golang.org/x/[email protected] h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
    golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y=
    golang.org/x/[email protected] h1:bUO06HqtnRcc/7l71XBe4WcqTZ+3AH1J59zWDDwLKgU=
    golang.org/x/[email protected] h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E=
    golang.org/x/[email protected] h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s=
    golang.org/x/[email protected] h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58=
    golang.org/x/[email protected] h1:5PWemM67wMSPpO0Y3lOPlyvgO3z56YkZRxPFcdd300g=
    golang.org/x/[email protected] h1:A9kONVi4+AnuOr1dopsibH6hLi1Huy54cbeJxnq4vmU=
    honnef.co/go/[email protected] h1:6qXr+R5w+ktL5UkwEbPp+fEvfyoMPche6GkOpGHZcLc=
    mvdan.cc/[email protected] h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM=
    mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc=
go: go1.20.4

go env

$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/reducted/Library/Caches/go-build"
GOENV="/Users/reducted/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/reducted/go/pkg/mod"
GONOPROXY="reducted"
GONOSUMDB="reducted"
GOOS="darwin"
GOPATH="/Users/reducted/go"
GOPRIVATE="reducted"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/opt/homebrew/Cellar/go/1.20.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/opt/homebrew/Cellar/go/1.20.4/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
AR="ar"
CC="cc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="reducted"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6_/msm1_r211ds7gwg7dv3zw8j40000gn/T/go-build420238562=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

A bugged snippet:

package main

type Helloer interface {
	Hello() string
}

type Bob struct{}
func (b *Bob) Hello() string {
	return "Hello, I'm Bob"
}

type GreetingMachine[T Helloer] struct {
	Greeter T
}
func (gm *GreetingMachine[T]) GreetFunc(f func(T)) { // pointer receiver here
	f(gm.Greeter)
}


func main() {
	gm := &GreetingMachine[*Bob]{
		Greeter: &Bob{},
	}
	// try autocomplete on `gm.GreetFunc(f)`
	gm.GreetFunc(func(t T) {})  // autocomplete here gives `func(t T) {}`
}

A working version:

package main

type Helloer interface {
	Hello() string
}

type Bob struct{}
func (b *Bob) Hello() string {
	return "Hello, I'm Bob"
}

type GreetingMachine[T Helloer] struct {
	Greeter T
}
func (gm GreetingMachine[T]) GreetFunc(f func(T)) {  // change to a value receiver
	f(gm.Greeter)
}


func main() {
	gm := &GreetingMachine[*Bob]{
		Greeter: &Bob{},
	}
	// try autocomplete on `gm.GreetFunc(f)`
	gm.GreetFunc(func(b *Bob) {})  // autocomplete here gives `func(b *Bob) {}`
}

What did you expect to see?

See the comment on the snippet code above.

What did you see instead?

See the comment on the snippet code above.

Editor and settings

VSCode

Logs

Nothing useful...

@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 Jul 6, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jul 6, 2023
@findleyr findleyr modified the milestones: Unreleased, gopls/v0.13.0 Jul 6, 2023
@findleyr
Copy link
Member

findleyr commented Jul 6, 2023

Thanks!

This is clearly a bug. Prioritizing for [email protected].

@findleyr findleyr added the gopls/generics Issues related to gopls' support for generics label Aug 16, 2023
@adonovan adonovan added the gopls/completion Issues related to auto-completion in gopls. label Aug 31, 2023
@findleyr findleyr modified the milestones: gopls/v0.14.0, gopls/v0.15.0 Sep 15, 2023
@gopherbot
Copy link
Contributor

Change https://go.dev/cl/539677 mentions this issue: gopls/internal/lsp/source: fix signatureHelp with pointer receivers

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