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: runtime error: index out of range if generic type's method never called #49667

Closed
squareheadc opened this issue Nov 19, 2021 · 3 comments
Labels
NeedsInvestigation
Milestone

Comments

@squareheadc
Copy link

@squareheadc squareheadc commented Nov 19, 2021

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

$ go version
go version devel go1.18-e8cda0a Fri Nov 19 00:05:59 2021 +0000 darwin/amd64

Does this issue reproduce with the latest release?

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/squarehead/Library/Caches/go-build"
GOENV="/Users/squarehead/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/squarehead/Program/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/squarehead/Program/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/squarehead/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/squarehead/sdk/gotip/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="devel go1.18-e8cda0a Fri Nov 19 00:05:59 2021 +0000"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/squarehead/Program/go/src/play/generic/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/28/rqpspsvd3ysgqk9bqth_tx1c0000gn/T/go-build3854113625=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

package a

type A[T any] struct {
}

func (a A[T]) F() {
	_ = a
}
package b

import "a"

type B[T any] struct {
	_ a.A[T]
}
package main

import "b"

func main() {
	var _ b.B[int]
}

What did you expect to see?

What did you see instead?

panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
cmd/compile/internal/typecheck.(*importReader).readFuncDcls.func1(...)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/typecheck/iimport.go:1174
cmd/compile/internal/typecheck.(*importReader).readFuncDcls(0x4?, 0xc000320580)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/typecheck/iimport.go:1182 +0x245
cmd/compile/internal/typecheck.(*importReader).funcBody(0xc000330c60, 0xc000320580)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/typecheck/iimport.go:1125 +0x65
cmd/compile/internal/typecheck.(*importReader).doInline(0xc0000fd400?, 0xc000320580)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/typecheck/iimport.go:1092 +0x99
cmd/compile/internal/typecheck.ImportBody(0xc000320580)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/typecheck/iimport.go:80 +0x206
cmd/compile/internal/noder.checkFetchBody(0xc000329860)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:638 +0x96
cmd/compile/internal/noder.(*genInst).getInstantiation(0x1f87a20, 0xc000329860, {0xc00000e188, 0x1, 0x1000189c6c0?}, 0x20?)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:659 +0x5a
cmd/compile/internal/noder.(*genInst).instantiateMethods(0xc0000fd6b0?)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:585 +0x24e
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1f87a20, 0x1)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:60 +0x3a
cmd/compile/internal/noder.BuildInstantiations(...)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/noder/stencil.go:47
cmd/compile/internal/noder.(*irgen).generate(0xc000338000, {0xc000312470, 0x2, 0x203000?})
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:320 +0x3db
cmd/compile/internal/noder.check2({0xc000312470, 0x2, 0x2})
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc0000bc100, 0x2, 0x0?})
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0x1943f08)
	/Users/squarehead/sdk/gotip/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
	/Users/squarehead/sdk/gotip/src/cmd/compile/main.go:55 +0xdd
@ALTree ALTree added this to the Go1.18 milestone Nov 19, 2021
@ALTree ALTree added the NeedsInvestigation label Nov 19, 2021
@ALTree
Copy link
Member

@ALTree ALTree commented Nov 19, 2021

cc @randall77 @danscales

@danscales danscales self-assigned this Nov 19, 2021
@danscales
Copy link
Contributor

@danscales danscales commented Nov 19, 2021

Thanks for the issue and test case! I'm working on this, have the simple fix.

@gopherbot
Copy link

@gopherbot gopherbot commented Nov 19, 2021

Change https://golang.org/cl/365837 mentions this issue: cmd/compile: ensure generic function is loaded when it needs to be re-exported

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

4 participants