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

plugin: types on different scopes when using vendor #30838

Closed
jschintag opened this issue Mar 14, 2019 · 2 comments
Closed

plugin: types on different scopes when using vendor #30838

jschintag opened this issue Mar 14, 2019 · 2 comments

Comments

@jschintag
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.12 linux/s390x

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env

GOARCH="s390x"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="s390x"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/root/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/go"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_s390x"
GCCGO="gccgo"
CC="s390x-linux-gnu-gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -march=z196 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build249750574=/tmp/go-build -gno-record-gcc-switches"

What did you do?

I have the following structure:

/root/go/src/
|-- foo
    |-- main.go
    |-- types/
        |-- types.go
|-- foo-plugin
    |-- plugin.go

I have an interface in types.go

types/types.go

package types

type Custom interface {
        Test() string
}

I use this in the Plugin

plugin.go

package main

import (
        "foo/types"
)

type CustomStruct struct {
}

var CustomVar types.Custom = &CustomStruct{}

func (c *CustomStruct) Test() string {
        return "success"
}

And i load and use the Plugin in main.go

main.go

package main

import (
        "fmt"
        "plugin"

        "foo/types"
)

func main() {
        p, err := plugin.Open("/root/go/src/foo-plugin/foo-plugin.so")
        if err != nil {
                fmt.Println(err)
        }
        symbol, err := p.Lookup("CustomVar")
        customVar := symbol.(*types.Custom)
        custom := *customVar
        result := custom.Test()
        fmt.Println(result)
}

When i build the Plugin and then run go run main.go it works.
However, when i copy foo into foo-plugin/vendor/foo i get an error.

What did you expect to see?

$ go run main.go
success

What did you see instead?

$ go run main.go
panic: interface conversion: plugin.Symbol is *types.Custom, not *types.Custom (types from different scopes)

goroutine 1 [running]:
main.main()
        /root/go/src/foo/main.go:16 +0x27e
exit status 2
@bcmills
Copy link
Contributor

bcmills commented Mar 14, 2019

In GOPATH mode, each vendor copy of a package is its own distinct package. That behavior will not be changing.

The solution is not to use vendor, or to use module mode with only a top-level vendor directory.

@bcmills bcmills closed this as completed Mar 14, 2019
@jschintag
Copy link
Author

Ok, thank you for your answer.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants