dominikh / go-tools

Staticcheck - The advanced Go linter
https://staticcheck.dev
MIT License
6.1k stars 368 forks source link

ssa: recursive interface causes stack overflow #310

Open elagergren-spideroak opened 6 years ago

elagergren-spideroak commented 6 years ago

Not entirely sure if this is a bug in your SSA package or x/tools/go/types, but this interface causes a stack overflow:

package tmp

type A interface {
    A() interface {
        A
    }
}

func main() {}

A snippet of the stack:

golang.org/x/tools/go/types/typeutil.Hasher.hashFor(0xc420186ab0, 0x1575f00, 0xc4200a1e00, 0x17d1500)
    /Users/elagergren/gopath/src/golang.org/x/tools/go/types/typeutil/map.go:285 +0x26b fp=0xc440195078 sp=0xc440194fd8 pc=0x1201c2b
...additional frames elided...
created by honnef.co/go/tools/ssa.(*Program).Build
    /Users/XX/gopath/src/honnef.co/go/tools/ssa/builder.go:2243 +0x11a
dominikh commented 6 years ago

This is now https://github.com/golang/go/issues/26863

elagergren-spideroak commented 6 years ago

@dominikh appreciate it.

qarmin commented 2 months ago
package p
type A[P any] [1]P
type B[P any] A[P]
type C /* ERROR "invalid recursive type" */ B[C]

is similar problem?

runtime: goroutine stack exceeds 1000000000-byte limit
runtime: sp=0xc020460388 stack=[0xc020460000, 0xc040460000]
fatal error: stack overflow

runtime stack:
runtime.throw({0xdf97fc?, 0x1?})
    runtime/panic.go:1023 +0x5c fp=0xc000073dd0 sp=0xc000073da0 pc=0x446dfc
runtime.newstack()
    runtime/stack.go:1103 +0x79b fp=0xc000073fc8 sp=0xc000073dd0 pc=0x463b1b
runtime.morestack()
    runtime/asm_amd64.s:616 +0x7a fp=0xc000073fd0 sp=0xc000073fc8 pc=0x48155a

goroutine 1 gp=0xc0000061c0 m=3 mp=0xc00005f008 [running]:
cmd/compile/internal/types2.(*Named).Underlying(0xc0000deee0?)
    cmd/compile/internal/types2/named.go:457 +0x5a fp=0xc020460398 sp=0xc020460390 pc=0xc50a3a
cmd/compile/internal/noder.isNotInHeap({0xf5b1a8?, 0xc0000deee0?})
...
dominikh commented 2 months ago

@qarmin that is a bug in Go 1.22 that is fixed in Go 1.23.