fix: substitute recursive struct type by interface{} in function arguments

This commit is contained in:
Marc Vertes
2020-03-19 12:42:05 +01:00
committed by GitHub
parent daaeac6e2c
commit b52dd8cc08
3 changed files with 28 additions and 3 deletions

24
_test/struct38.go Normal file
View File

@@ -0,0 +1,24 @@
package main
type T struct {
f func(t *T1)
y *xxx
}
type T1 struct {
T
}
type xxx struct{}
var (
x1 *T1 = x
x = &T1{}
)
func main() {
println("ok")
}
// Output:
// ok

View File

@@ -1,8 +1,6 @@
package interp
import (
"reflect"
)
import "reflect"
// gta performs a global types analysis on the AST, registering types,
// variables and functions symbols at package level, prior to CFG.

View File

@@ -905,6 +905,9 @@ var interf = reflect.TypeOf(new(interface{})).Elem()
func (t *itype) refType(defined map[string]*itype, wrapRecursive bool) reflect.Type {
if t.rtype != nil {
if wrapRecursive && t.cat == structT && defined[t.name] != nil {
return interf
}
return t.rtype
}