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

cmd/compile: panic in generics (types from different scopes on interface conversion) #53376

Closed
ernado opened this issue Jun 14, 2022 · 5 comments
Closed
Labels
NeedsInvestigation
Milestone

Comments

@ernado
Copy link
Contributor

@ernado ernado commented Jun 14, 2022

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

go version go1.18.3 linux/amd64

Does this issue reproduce with the latest release?

Yes, also on go version devel go1.19-55590f3a2b Works on tip

But works on 1.18.2, so prorably a regression?

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

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

What did you do?

https://go.dev/play/p/WSzdK-I-g2o

type Appender[T any] interface {
	Append(v T)
}

type StrAppender struct{}

func (StrAppender) Append(v string) {}

func newStrAppender() Appender[string] {
	return StrAppender{}
}

// this works
func appendAllGood[T any, C Appender[T]](c C, v ...T) C {
	for _, vv := range v {
		c.Append(vv)
	}
	return c
}

// this panics on go1.18.3, go1.19, but works on go1.18.2
func appendAllBad[T any](c Appender[T], v ...T) Appender[T] {
	for _, vv := range v {
		c.Append(vv) // <- panic: interface conversion: 
		// pkg.Appender[go.shape.string_0] is pkg.StrAppender, not pkg.StrAppender 
		// (types from different scopes)
	}
	return c
}

What did you expect to see?

No panic

What did you see instead?

panic: interface conversion: main.Appender[go.shape.string_0] is main.StrAppender, not main.StrAppender (types from different scopes)

goroutine 1 [running]:
main.appendAllBad[...](...)
	/tmp/sandbox1272243070/prog.go:28
main.main()
	/tmp/sandbox1272243070/prog.go:37 +0x116

Program exited.
@ianlancetaylor ianlancetaylor changed the title runtime: panic in generics (types from different scopes on interface conversion) cmd/compile: panic in generics (types from different scopes on interface conversion) Jun 14, 2022
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 14, 2022

CC @randall77 @mdempsky

@ianlancetaylor ianlancetaylor added the NeedsInvestigation label Jun 14, 2022
@ianlancetaylor ianlancetaylor added this to the Go1.19 milestone Jun 14, 2022
@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jun 14, 2022

Looks to be working at tip?

@ernado
Copy link
Contributor Author

@ernado ernado commented Jun 14, 2022

@mdempsky

ernado@nexus:/src/ernado/types-from-different-scope$ /src/go/bin/go version
go version devel go1.19-cad477c922 Tue Jun 14 14:49:40 2022 +0000 linux/amd64
ernado@nexus:/src/ernado/types-from-different-scope$ /src/go/bin/go test
--- FAIL: TestBad (0.00s)
panic: interface conversion: pkg.Appender[go.shape.string_0] is pkg.StrAppender, not pkg.StrAppender (types from different scopes) [recovered]
        panic: interface conversion: pkg.Appender[go.shape.string_0] is pkg.StrAppender, not pkg.StrAppender (types from different scopes)

goroutine 7 [running]:
testing.tRunner.func1.2({0x503040, 0xc0000103f0})
        /usr/local/go/src/testing/testing.go:1389 +0x24e
testing.tRunner.func1()
        /usr/local/go/src/testing/testing.go:1392 +0x39f
panic({0x503040, 0xc0000103f0})
        /usr/local/go/src/runtime/panic.go:838 +0x207
types-from-different-scope.appendAllBad[...](...)
        /src/ernado/types-from-different-scope/main_test.go:26
types-from-different-scope.TestBad(0xc0000e4340?)
        /src/ernado/types-from-different-scope/main_test.go:38 +0x2e
testing.tRunner(0xc0000e4680, 0x528670)
        /usr/local/go/src/testing/testing.go:1439 +0x102
created by testing.(*T).Run
        /usr/local/go/src/testing/testing.go:1486 +0x35f
exit status 2
FAIL    types-from-different-scope      0.003s

Not working on cad477c (but works on playground "dev branch" tho)

My repro repo https://github.com/ernado/types-from-different-scope

git clone https://github.com/ernado/types-from-different-scope.git
cd types-from-different-scope/

@ernado
Copy link
Contributor Author

@ernado ernado commented Jun 14, 2022

Sorry @mdempsky, actually this works on tip (cad477c), got some very weird go env

So it is regression between go1.18.2 and go1.18.3 that was fixed on tip

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 24, 2022

Working at tip, so closing. Thanks.

@ianlancetaylor ianlancetaylor closed this as not planned Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
Development

No branches or pull requests

3 participants