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: slice bounds out of range panic on generic code #49497

Closed
rogpeppe opened this issue Nov 10, 2021 · 2 comments
Closed

cmd/compile: slice bounds out of range panic on generic code #49497

rogpeppe opened this issue Nov 10, 2021 · 2 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@rogpeppe
Copy link
Contributor

go version devel go1.18-17980dff36 Wed Nov 10 05:08:25 2021 +0000 linux/amd64

What did you do?

Run testscript on the following txtar file:

go test
-- go.mod --
module example.com/m

go 1.18
-- m.go --
package m

func F[T any]() A[T] {
	panic("unreachable")
}

type A[T any] struct {
	b B[T]
}

func (a A[T]) M() C[T] {
	return C[T]{
		B: a.b,
	}
}

type B[T any] struct{}

type C[T any] struct {
	B B[T]
}
-- m_test.go --
package m_test

import (
	"testing"

	"example.com/m"
)

func TestF(t *testing.T) {
	m.F[string]()
}

I see a panic with the following stack trace:

panic: runtime error: slice bounds out of range [:-1]

goroutine 1 [running]:
cmd/compile/internal/typecheck.genericTypeName(...)
	/home/rogpeppe/go/src/cmd/compile/internal/typecheck/subr.go:1402
cmd/compile/internal/typecheck.(*Tsubster).typ1(0xc0005afd68, 0xc0005ae1c0)
	/home/rogpeppe/go/src/cmd/compile/internal/typecheck/subr.go:1106 +0x13dd
cmd/compile/internal/typecheck.(*Tsubster).Typ(0x59728b?, 0x4?)
	/home/rogpeppe/go/src/cmd/compile/internal/typecheck/subr.go:1046 +0x25
cmd/compile/internal/noder.(*subster).node.func1({0xe892b8, 0xc00068d520?})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:903 +0x305
cmd/compile/internal/ir.(*KeyExpr).editChildren(0xc000374180, 0xc000684c30)
	/home/rogpeppe/go/src/cmd/compile/internal/ir/node_gen.go:792 +0x62
cmd/compile/internal/ir.EditChildren(...)
	/home/rogpeppe/go/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*subster).node.func1({0xe88e08, 0xc000374060?})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:955 +0x52f
cmd/compile/internal/ir.editNodes(...)
	/home/rogpeppe/go/src/cmd/compile/internal/ir/node_gen.go:1521
cmd/compile/internal/ir.(*CompLitExpr).editChildren(0xc0005b2080, 0xc000684c30)
	/home/rogpeppe/go/src/cmd/compile/internal/ir/node_gen.go:405 +0x171
cmd/compile/internal/ir.EditChildren(...)
	/home/rogpeppe/go/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*subster).node.func1({0xe880c0, 0xc0005b2000?})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:955 +0x52f
cmd/compile/internal/ir.editNodes(...)
	/home/rogpeppe/go/src/cmd/compile/internal/ir/node_gen.go:1521
cmd/compile/internal/ir.(*ReturnStmt).editChildren(0xe89830?, 0xc000684c30)
	/home/rogpeppe/go/src/cmd/compile/internal/ir/node_gen.go:1056 +0xa2
cmd/compile/internal/ir.EditChildren(...)
	/home/rogpeppe/go/src/cmd/compile/internal/ir/visit.go:185
cmd/compile/internal/noder.(*subster).node.func1({0xe89830, 0xc0004e3130?})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:955 +0x52f
cmd/compile/internal/noder.(*subster).node(0xc0005afd50, {0xe89830, 0xc0004e3130})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:1171 +0xa5
cmd/compile/internal/noder.(*subster).list(0xc00000fda0?, {0xc0005464c0, 0x1, 0xc00051cfa0?})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:1426 +0x8e
cmd/compile/internal/noder.(*genInst).genericSubst(0x1382d60, 0xc0004e31d0, 0xc00068dc70, {0xc00000fd18, 0x1, 0x1}, 0x1, 0xc000684ae0)
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:803 +0xce6
cmd/compile/internal/noder.(*genInst).getInstantiation(0x1382d60, 0xc00068dc70, {0xc00000fc70, 0x1, 0x7fed55649418?}, 0x39?)
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:680 +0x298
cmd/compile/internal/noder.(*genInst).instantiateMethods(0x40cdc5?)
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:577 +0x24e
cmd/compile/internal/noder.(*genInst).buildInstantiations(0x1382d60, 0x1)
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:60 +0x3a
cmd/compile/internal/noder.BuildInstantiations(...)
	/home/rogpeppe/go/src/cmd/compile/internal/noder/stencil.go:47
cmd/compile/internal/noder.(*irgen).generate(0xc00016a240, {0xc00000e420, 0x1, 0x203000?})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/irgen.go:320 +0x3db
cmd/compile/internal/noder.check2({0xc00000e420, 0x1, 0x1})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/irgen.go:92 +0x16d
cmd/compile/internal/noder.LoadPackage({0xc00001e220, 0x1, 0x0?})
	/home/rogpeppe/go/src/cmd/compile/internal/noder/noder.go:90 +0x335
cmd/compile/internal/gc.Main(0xd42fd0)
	/home/rogpeppe/go/src/cmd/compile/internal/gc/main.go:191 +0xb13
main.main()
	/home/rogpeppe/go/src/cmd/compile/main.go:55 +0xdd

If I change the name of the field C.B to C.b, it doesn't panic.

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

Yes, it looks to be a confusion on the name 'B' during import of package m into m_test. I'll investigate further.

@danscales danscales added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 10, 2021
@danscales danscales added this to the Go1.18 milestone Nov 10, 2021
@gopherbot
Copy link

Change https://golang.org/cl/363074 mentions this issue: cmd/compile: don't do Resolve on OKEY identifiers during import

@golang golang locked and limited conversation to collaborators Jun 23, 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.
Projects
None yet
Development

No branches or pull requests

3 participants