fix: avoid infinite loop when parsing recursive types

Mark all visited types as such when walking down struct fields.

Fixes #750.
Updates #652.
This commit is contained in:
Marc Vertes
2020-07-06 15:30:04 +02:00
committed by GitHub
parent 851444453c
commit 2a70a71dc2
2 changed files with 25 additions and 0 deletions

23
_test/struct53.go Normal file
View File

@@ -0,0 +1,23 @@
package main
import "fmt"
type T1 struct {
P []*T
}
type T2 struct {
P2 *T
}
type T struct {
*T1
S1 *T
}
func main() {
fmt.Println(T2{})
}
// Output:
// {<nil>}

View File

@@ -1385,6 +1385,8 @@ func hasRecursiveStruct(t *itype, defined map[string]*itype) bool {
if defined[typ.path+"/"+typ.name] != nil {
return true
}
defined[typ.path+"/"+typ.name] = typ
for _, f := range typ.field {
if hasRecursiveStruct(f.typ, defined) {
return true