Closed
Description
What version of Go are you using (go version
)?
$ go version go version go1.18 windows/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 set GO111MODULE= set GOARCH=amd64 set GOBIN= set GOCACHE=C:\Users\vogtp\AppData\Local\go-build set GOENV=C:\Users\vogtp\AppData\Roaming\go\env set GOEXE=.exe set GOEXPERIMENT= set GOFLAGS= set GOHOSTARCH=amd64 set GOHOSTOS=windows set GOINSECURE= set GOMODCACHE=C:\Users\vogtp\go\pkg\mod set GONOPROXY=gitlab-int.its.unibas.ch set GONOSUMDB=gitlab-int.its.unibas.ch set GOOS=windows set GOPATH=C:\Users\vogtp\go set GOPRIVATE=gitlab-int.its.unibas.ch set GOPROXY=https://proxy.golang.org,direct set GOROOT=C:\Users\vogtp\sdk\go1.18 set GOSUMDB=sum.golang.org set GOTMPDIR= set GOTOOLDIR=C:\Users\vogtp\sdk\go1.18\pkg\tool\windows_amd64 set GOVCS= set GOVERSION=go1.18 set GCCGO=gccgo set GOAMD64=v1 set AR=ar set CC=gcc set CXX=g++ set CGO_ENABLED=1 set GOMOD=C:\Users\vogtp\go\src\gitlab-int.its.unibas.ch\vogtp\murx\go.mod set GOWORK= set CGO_CFLAGS=-g -O2 set CGO_CPPFLAGS= set CGO_CXXFLAGS=-g -O2 set CGO_FFLAGS=-g -O2 set CGO_LDFLAGS=-g -O2 set PKG_CONFIG=pkg-config set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\vogtp\AppData\Local\Temp\go-build1961016563=/tmp/go-build -gno-record-gcc-switches
What did you do?
https://go.dev/play/p/TgQFW3CWM12
What did you expect to see?
A error with a file and a line number, I can goto and fix.
What did you see instead?
:1: internal compiler error: panic: runtime error: index out of range [0] with length 0
Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new
Go build failed.
I really did not expect a request for a bug report, but here it is! ;-)
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
[-]affected/package: [/-][+]runtime/generics: [/+]vogtp commentedon Apr 5, 2022
I just realised that changing
func (h *msgHandler[M]) Handle(msgHandler func(e *M)) error
to
func (h *msgHandler[M]) Handle(f func(e *M)) error
fixes the problem in my demo code, but not in my production code.
https://go.dev/play/p/UnIXXd3PS4Z
earthboundkid commentedon Apr 5, 2022
Here is a shorter reproducer:
https://go.dev/play/p/pn99Ydje_nL
I think part of the problem is that the callback is named the same as the generic type.
earthboundkid commentedon Apr 5, 2022
Even shorter:
ianlancetaylor commentedon Apr 5, 2022
CC @randall77 @mdempsky
ianlancetaylor commentedon Apr 5, 2022
This works in 1.18.
[-]runtime/generics: [/-][+]cmd/compile: compiler crash on generic code[/+][-]cmd/compile: compiler crash on generic code[/-][+]cmd/compile: ICE: "runtime error: index out of range [0] with length 0" due to generic code[/+]mdempsky commentedon Apr 5, 2022
@ianlancetaylor
Do you mean this works at tip? The playground links are for Go 1.18, which are reproducing the issue.
I'm not able to reproduce at tip. I am able to reproduce with "go1.18-pre13".
ianlancetaylor commentedon Apr 5, 2022
Interesting. I can reproduce the crash with
but I can't reproduce it with
ianlancetaylor commentedon Apr 5, 2022
And I can't reproduce it on tip.
Sounds like this has been fixed.