Skip to content

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

Closed
@rguilmont

Description

@rguilmont

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 !

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions