go: runtime: in generic code, convert iface to type failed with "types from different scopes"

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

go version go1.18beta2 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/romain/.cache/go-build"
GOENV="/home/romain/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/romain/go/pkg/mod"
GONOPROXY="XXXXXXXXXXXXXXXXXXX"
GONOSUMDB="XXXXXXXXXXXXXXXXXXX"
GOOS="linux"
GOPATH="/home/romain/go"
GOPRIVATE="XXXXXXXXXXXXXXXXX"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/romain/sdk/go1.18beta2"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/romain/sdk/go1.18beta2/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18beta2"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/romain/Documents/git/github/replicate-issue/types-from-different-scopes-issue/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build838965849=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Using generics and interface conversion, i get the following error at runtime :

panic: interface conversion: either.Either[go.shape.string_0,go.shape.interface {}_1] is either.right[github.com/rguilmont/types-from-different-scopes-issue/pkg/pkga.Test,interface {}], not either.right[github.com/rguilmont/types-from-different-scopes-issue/pkg/pkga.Test,interface {}] (types from different scopes)

goroutine 1 [running]:
github.com/rguilmont/types-from-different-scopes-issue/pkg/either.Fold[...]({0x4b2c00, 0xc00009e210}, 0x49c850, 0x49c858)
        /home/romain/Documents/git/github/replicate-issue/types-from-different-scopes-issue/pkg/either/either.go:42 +0xc5
main.main()
        /home/romain/Documents/git/github/replicate-issue/types-from-different-scopes-issue/pkg/cmd/main.go:13 +0x65

To check the code, here it is with instruction to replicate : https://github.com/rguilmont/types-from-different-scopes-issue

What did you expect to see?

It works! test

Thanks !

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (10 by maintainers)

Commits related to this issue

Most upvoted comments

There is a CL that fixes this issue. I’m investigating a possibly better fix, should know one way or another by EOD.

Reopening for cherry-picking into 1.18 release branch.

Hm, looks like when compiling pkga, we make a symbol right["".Test,interface {}] in package either. But the "" in that symbol refers to pkga. But right is in package either, so we use either to substitute into the symbol name, which is not always right.

Thanks for the report. I don’t know generics to say if this is expected or not, but I checked and this behavior reproduces with go1.18rc1 as well.

CC @findleyr, @mdempsky.