From b52dd8cc08296875eb6bd5dc26496f06f85830ab Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Thu, 19 Mar 2020 12:42:05 +0100 Subject: [PATCH] fix: substitute recursive struct type by interface{} in function arguments --- _test/struct38.go | 24 ++++++++++++++++++++++++ interp/gta.go | 4 +--- interp/type.go | 3 +++ 3 files changed, 28 insertions(+), 3 deletions(-) create mode 100644 _test/struct38.go diff --git a/_test/struct38.go b/_test/struct38.go new file mode 100644 index 00000000..8d1973b6 --- /dev/null +++ b/_test/struct38.go @@ -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 diff --git a/interp/gta.go b/interp/gta.go index 79d5c79c..209a58d0 100644 --- a/interp/gta.go +++ b/interp/gta.go @@ -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. diff --git a/interp/type.go b/interp/type.go index c12e735f..dde6970f 100644 --- a/interp/type.go +++ b/interp/type.go @@ -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 }