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

go/types, types2: go generic assert compile escape #52228

Closed
elvizlai opened this issue Apr 8, 2022 · 7 comments
Closed

go/types, types2: go generic assert compile escape #52228

elvizlai opened this issue Apr 8, 2022 · 7 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Milestone

Comments

@elvizlai
Copy link

elvizlai commented Apr 8, 2022

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

$ go version
go version go1.18 darwin/amd64
same behavior on linux/amd64

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="amd64"
GOBIN=""
GOCACHE="/Users/elvizlai/Library/Caches/go-build"
GOENV="/Users/elvizlai/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/elvizlai/.godeps/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/elvizlai/.godeps"
GOPRIVATE=""
GOPROXY="https://goproxy.cn|https://goproxy.io|https://goproxy.baidu.com/|https://mirrors.tencent.com/go/|direct"
GOROOT="/Users/elvizlai/.g/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/elvizlai/.g/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.18"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/elvizlai/temp/go-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 -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/hs/cwct781947971m14gv8vm8s00000gn/T/go-build695014846=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go run main.go

package main

type SomeInterface interface {
	Whatever()
}

func X[T any]() T {
	var m T

	// for this example, this block should never run
	if _, ok := any(m).(SomeInterface); ok {
		var dst SomeInterface
		_, _ = dst.(T) // remove this works fine
		return dst.(T)
	}

	return m
}

type holder struct{}

func main() {
	X[holder]()
}

What did you expect to see?

run then exist 0 or there this can not compiled.

What did you see instead?

panic: interface conversion: main.SomeInterface is nil, not main.holder

goroutine 1 [running]:
main.X[...](...)
	/Users/elvizlai/temp/go-issue/main.go:14
main.main()
	/Users/elvizlai/temp/go-issue/main.go:23 +0x65
exit status 2
@mengzhuo mengzhuo changed the title affected/runtime: go generic assert compile escape go/types, types2: go generic assert compile escape Apr 8, 2022
@mengzhuo mengzhuo added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 8, 2022
@mengzhuo
Copy link
Contributor

mengzhuo commented Apr 8, 2022

cc @griesemer

@elvizlai
Copy link
Author

elvizlai commented Apr 8, 2022

maybe a helpful tricks in X func: wrap dst with any(dst) can “fix” panic. But I think origin code should be worked or not compilable.

@wdvxdr1123
Copy link
Contributor

may related with #51700, I noticed they both failed with two type assert.

@gopherbot
Copy link

Change https://go.dev/cl/399058 mentions this issue: cmd/compile: always write fun[0] in incompelte itab

@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Apr 8, 2022
@ianlancetaylor
Copy link
Contributor

@gopherbot Please open backport to 1.18

This is valid code that is being compiled incorrectly.

@gopherbot
Copy link

Backport issue(s) opened: #52244 (for 1.18).

Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.

@ianlancetaylor
Copy link
Contributor

CC @randall77 @mdempsky

@golang golang locked and limited conversation to collaborators Apr 12, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants