You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying Golang generics and catch a strange behavior: stack overflow with simple code. If I write the same code with a specific type, it will work as expected. You can check it on playground.
The minimal code is:
func test[A ~[]T, T comparable](arr ...A) A {
var ret A
switch len(arr) {
case 0, 1, 2:
return ret
default:
return test(arr[2:]...)
}
}
What did you expect to see?
no fatal error
What did you see instead?
runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020460468 stack=[0xc020460000, 0xc040460000]
fatal error: stack overflow
runtime stack:
runtime.throw({0xd21d63?, 0x12eb300?})
/usr/local/go/src/runtime/panic.go:992 +0x71
runtime.newstack()
/usr/local/go/src/runtime/stack.go:1101 +0x5cc
runtime.morestack()
/usr/local/go/src/runtime/asm_amd64.s:547 +0x8b
goroutine 1 [running]:
cmd/compile/internal/types2.(*unifier).nify(0xc00016e630, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0)
/usr/local/go/src/cmd/compile/internal/types2/unify.go:239 +0x11c5 fp=0xc020460478 sp=0xc020460470 pc=0xba1505
cmd/compile/internal/types2.(*unifier).nifyEq(0x0?, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0?)
/usr/local/go/src/cmd/compile/internal/types2/unify.go:232 +0x96 fp=0xc0204604d8 sp=0xc020460478 pc=0xba02d6
cmd/compile/internal/types2.(*unifier).nify(0xc00016e630, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0)
/usr/local/go/src/cmd/compile/internal/types2/unify.go:266 +0x314 fp=0xc020460678 sp=0xc0204604d8 pc=0xba0654
cmd/compile/internal/types2.(*unifier).nifyEq(0x0?, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0?)
/usr/local/go/src/cmd/compile/internal/types2/unify.go:232 +0x96 fp=0xc0204606d8 sp=0xc020460678 pc=0xba02d6
cmd/compile/internal/types2.(*unifier).nify(0xc00016e630, {0xe8e7c0?, 0xc0003cfcb0?}, {0xe8e748?, 0xc00002d130?}, 0x0)
/usr/local/go/src/cmd/compile/internal/types2/unify.go:266 +0x314 fp=0xc020460878 sp=0xc0204606d8 pc=0xba0654
...additional frames elided...
Go build failed.
About the Playground
The Go Playground is a web service that runs on go.dev's servers. The service receives a Go program, vets, compiles, links, and runs the program inside a sandbox, then returns the output.
The text was updated successfully, but these errors were encountered:
nikgalushko
changed the title
Go1.18: stack overflow with generic function
Go1.18: runtime: goroutine stack exceeds 1000000000-byte limit with generic function
Dec 20, 2021
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
No.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I'm trying Golang generics and catch a strange behavior: stack overflow with simple code. If I write the same code with a specific type, it will work as expected. You can check it on playground.
The minimal code is:
What did you expect to see?
no fatal error
What did you see instead?
The text was updated successfully, but these errors were encountered: