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:
23
_test/struct53.go
Normal file
23
_test/struct53.go
Normal 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>}
|
||||||
@@ -1385,6 +1385,8 @@ func hasRecursiveStruct(t *itype, defined map[string]*itype) bool {
|
|||||||
if defined[typ.path+"/"+typ.name] != nil {
|
if defined[typ.path+"/"+typ.name] != nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
defined[typ.path+"/"+typ.name] = typ
|
||||||
|
|
||||||
for _, f := range typ.field {
|
for _, f := range typ.field {
|
||||||
if hasRecursiveStruct(f.typ, defined) {
|
if hasRecursiveStruct(f.typ, defined) {
|
||||||
return true
|
return true
|
||||||
|
|||||||
Reference in New Issue
Block a user