Skip to content

struct type conversion doesn't recursively evaluate type equivalence #58965

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

Closed
petemoore opened this issue Mar 10, 2023 · 1 comment
Closed

Comments

@petemoore
Copy link

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

$ go version
1.20.2

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
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/pmoore/Library/Caches/go-build"
GOENV="/Users/pmoore/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/pmoore/.gvm/pkgsets/go1.20.2/global/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/pmoore/.gvm/pkgsets/go1.20.2/global"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/pmoore/.gvm/gos/go1.20.2"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/pmoore/.gvm/gos/go1.20.2/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/pmoore/git/d2g/go.mod"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/kc/p5r32hgd42xcwxhc9lyfxtwm0000gn/T/go-build282360353=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package structconvert

type (
	A1 struct {
		Member B1
	}
	A2 struct {
		Member B2
	}
	B1 struct {
		Switch bool
	}
	B2 struct {
		Switch bool
	}
)

func Convert() {
	_ = B2(B1{}) // ok
	_ = A2(A1{}) // not ok
}

What did you expect to see?

I expected the code to compile. I raised as a bug, but perhaps it is intentional that struct type conversion doesn't recursively evaluate struct equivalence? I'm not sure why it shouldn't though.

Related: #19778

What did you see instead?

Compilation error: cannot convert A1{} (value of type A1) to type A2

@seankhliao
Copy link
Member

Duplicate of #18030

@seankhliao seankhliao marked this as a duplicate of #18030 Mar 10, 2023
@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Mar 10, 2023
@golang golang locked and limited conversation to collaborators Mar 9, 2024
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