Skip to content

cmd/compile: type inference appears to infer underlying types #50426

@ivokub

Description

@ivokub

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

$ go version 
go1.18beta1 linux/amd64

Does this issue reproduce with the latest release?

With Go 1.18 beta 1

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/ivo/.cache/go-build"
GOENV="/home/ivo/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/ivo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/ivo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/ivo/sdk/go1.18beta1"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/ivo/sdk/go1.18beta1/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.18beta1"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/ivo/Work/workspace/gnark/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-build1880804062=/tmp/go-build -gno-record-gcc-switches"


The situation is reproducible with Go Playground on develop.

What did you do?

Trying out union interface types. The following program does not compile:

type A1 [2]uint64
type A2 [2]uint64
func (a A1) Get() A1 {	return a}
func (a A2) Get() A2 {	return a}
type I[T any] interface {
	A1 | A2
	Get() T
}
func F[B any, T I[B]](v T) {	v.Get()}
func main() {
	v := A2{1, 2}
	F[A2](v)
}

Go Play link

However, when I add another type A3 [3]uint64, then compiles and runs:

type A1 [2]uint64
type A2 [2]uint64
type A3 [3]uint64
func (a A1) Get() A1 {	return a}
func (a A2) Get() A2 {	return a}
func (a A3) Get() A3 {  return a}
type I[T any] interface {
	A1 | A2 | A3 // <-- added A3
	Get() T
}
func F[B any, T I[B]](v T) {	v.Get()}
func main() {
	v := A2{1, 2}
	F[A2](v)
}

Go Play link

What did you expect to see?

Nothing

What did you see instead?

./prog.go:19:7: [2]uint64 does not implement I[A2] (missing method Get)

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.release-blocker

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions