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/go2go index out of range [0] with length 0 panic #39707

LastPossum opened this issue Jun 19, 2020 · 2 comments

cmd/go2go index out of range [0] with length 0 panic #39707

LastPossum opened this issue Jun 19, 2020 · 2 comments


Copy link

@LastPossum LastPossum commented Jun 19, 2020

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

$ go version
 devel +5f01333bf1 Wed Jun 17 04:20:54 2020 +0000. 

What did you do?

Try to run this code

package main

import (

type List(type T) interface{
	Head() T
	Tail() List(T)
	Add(T) List(T)
	Empty() bool

func NewList(type T)() List(T){
	return &nill(T){}

type list(type T) struct{
	head T
	tail List(T)

func (q *list(T)) Head() T{
	return q.head

func (q *list(T)) Tail() List(T){
	return q.tail

func (q *list(T)) Add(v T) List(T){
	return &list(T){
		head: v,
		tail: q,

func (*list(T)) Empty() bool{
	return false

type nill(type T) struct{}

func (*nill(T)) Head() T{
	panic("no head in nill list")
	var t T
	return t

func (*nill(T)) Tail() List(T){
	return &nill(T){}

func (n *nill(T)) Add(v T) List(T){
	return &list(T){
		head: v,
		tail: n,

func (q *nill(T)) Empty() bool{
	return true

func main() {
	lst := NewList(int)()
	for v := lst.Head(); !lst.Empty(); v = lst.Head(){

What did you expect to see?

I'm not shure, but not the panic.

What did you see instead?

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

goroutine 1 [running]:
go/go2go.(*translator).instantiateTypeDecl(0xc0004099b0, 0x0, 0xc00000c580, 0xc00007b3b0, 0xc000422040, 0x1, 0x1, 0xc000422150, 0x1, 0x1, ...)
	/usr/local/go-faketime/src/go/go2go/instantiate.go:201 +0xc45
go/go2go.(*translator).translateTypeInstantiation(0xc0004099b0, 0xc0003e9780)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:808 +0x4cd
go/go2go.(*translator).translateExpr(0xc0004099b0, 0xc0003e9780)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:616 +0x3bb
go/go2go.(*translator).translateExpr(0xc0004099b0, 0xc0003fa690)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:571 +0xf9
go/go2go.(*translator).translateExpr(0xc0004099b0, 0xc000422030)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:623 +0x1e5
go/go2go.(*translator).translateExprList(0xc0004099b0, 0xc000422030, 0x1, 0x1)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:693 +0x46
go/go2go.(*translator).translateStmt(0xc0004099b0, 0xc000422020)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:504 +0x225
go/go2go.(*translator).translateBlockStmt(0xc0004099b0, 0xc0003f96b0)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:455 +0x52
go/go2go.(*translator).translateFuncDecl(0xc0004099b0, 0xc000422060)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:448 +0xc5
go/go2go.(*translator).translate(0xc0004099b0, 0xc000104300)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:376 +0x391
go/go2go.rewriteAST(0xc000072240, 0xc0000553b0, 0x0, 0x0, 0xc000055b30, 0xc000104300, 0x1, 0xc000055360, 0xc000055b30)
	/usr/local/go-faketime/src/go/go2go/rewrite.go:188 +0x109
go/go2go.RewriteBuffer(0xc0000553b0, 0x7ffe6b956dd8, 0x1e, 0xc000138000, 0x38f, 0x58f, 0x0, 0xc000010a50, 0xc000010a20, 0xc0000109f0, ...)
	/usr/local/go-faketime/src/go/go2go/go2go.go:132 +0x2c5
main.translateFile(0xc0000553b0, 0x7ffe6b956dd8, 0x1e)
	/usr/local/go-faketime/src/cmd/go2go/translate.go:26 +0xa9
	/usr/local/go-faketime/src/cmd/go2go/main.go:64 +0x2ea
Copy link

@gopherbot gopherbot commented Jun 20, 2020

Change mentions this issue: [dev.go2go] go/go2go: don't crash on an unnamed receiver

Copy link

@ianlancetaylor ianlancetaylor commented Jun 20, 2020

Thanks for the test case. This is now fixed on the dev.go2go branch.

gopherbot pushed a commit that referenced this issue Jun 20, 2020
Fixes #39707

Change-Id: I20e5fe2990ceda5429f1a22edf48494d2c6496a2
Reviewed-by: Ian Lance Taylor <>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.