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: Cannot find method when using C structs #57781

Open
pedosb opened this issue Jan 13, 2023 · 1 comment
Open

x/tools/gopls: Cannot find method when using C structs #57781

pedosb opened this issue Jan 13, 2023 · 1 comment
Labels
gopls Issues related to the Go language server, gopls. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Milestone

Comments

@pedosb
Copy link

pedosb commented Jan 13, 2023

Hello!

gopls version

$ gopls version
golang.org/x/tools/gopls v0.11.0
    golang.org/x/tools/gopls@v0.11.0 h1:/nvKHdTtePQmrv9XN3gIUN9MOdUrKzO/dcqgbG6x8EY=

go env

$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/mine/Library/Caches/go-build"
GOENV="/Users/mine/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mine/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mine/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/mine/homebrew/Cellar/go/1.19.4/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/mine/homebrew/Cellar/go/1.19.4/libexec/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.4"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/mine/code/temp/go-with-cgo/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 arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2n/v_rmrnt16qbd3kt9jqb8g8sc0000gp/T/go-build4171816550=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

The code below compiles and runs just fine.

package main

import (
	"fmt"
)

/*
typedef struct number {
    int value;
} number_t;
*/
import "C"

func (n C.number_t) show() {
	fmt.Printf("%d\n", n.value)
}

func main() {
	var n C.number_t
	n.show()
}
$ go run main.go
0

However, gopls complains because it cannot find the "show method".

$ ~/go/bin/gopls check main.go
main.go:21:4-8: n.show undefined (type _Ctype_struct_number has no field or method show)

What did you expect to see?

I expected gopls to find all the references.

What did you see instead?

gopls did not find a reference to the show method, even though it is defined and found by the compiler.

Editor and settings

Using it in the command line. Even though I do not report it here, the same error appears in VSCode, given that it uses gopls.

Thanks ;)

@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 13, 2023
@gopherbot gopherbot added this to the Unreleased milestone Jan 13, 2023
@pedosb pedosb changed the title x/tools/gopls: x/tools/gopls: Cannot find declared method when using C structs Jan 13, 2023
@pedosb pedosb changed the title x/tools/gopls: Cannot find declared method when using C structs x/tools/gopls: Cannot find method when using C structs Jan 13, 2023
@adonovan
Copy link
Member

I question whether this program is valid as it attempts to declare a method on a type that is ostensibly defined in another package, which should be a syntax error; see #57926. Let's see what the outcome of that discussion is before we decide what to do in gopls.

@dle8 dle8 added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Jan 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gopls Issues related to the Go language server, gopls. NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. Tools This label describes issues relating to any tools in the x/tools repository. WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

4 participants