From 9214806342e1472d0568df6f16e2f8f977d07e79 Mon Sep 17 00:00:00 2001 From: Marc Vertes Date: Tue, 9 Nov 2021 11:26:11 +0100 Subject: [PATCH] interp: fix populating array of interfaces Fixes #1308. --- _test/issue-1308.go | 27 +++++++++++++++++++++++++++ interp/run.go | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 _test/issue-1308.go diff --git a/_test/issue-1308.go b/_test/issue-1308.go new file mode 100644 index 000000000..df59ac5ec --- /dev/null +++ b/_test/issue-1308.go @@ -0,0 +1,27 @@ +package main + +import "fmt" + +type test struct { + v interface{} + s string +} + +type T struct { + name string +} + +func main() { + t := []test{ + { + v: []interface{}{ + T{"hello"}, + }, + s: "world", + }, + } + fmt.Println(t) +} + +// Output: +// [{[{hello}] world}] diff --git a/interp/run.go b/interp/run.go index 92eeb9916..9d554b922 100644 --- a/interp/run.go +++ b/interp/run.go @@ -2588,7 +2588,7 @@ func doComposite(n *node, hasType bool, keyed bool) { values[fieldIndex] = func(*frame) reflect.Value { return reflect.New(rft).Elem() } case isFuncSrc(val.typ): values[fieldIndex] = genValueAsFunctionWrapper(val) - case isArray(val.typ) && val.typ.val != nil && isInterfaceSrc(val.typ.val): + case isArray(val.typ) && val.typ.val != nil && isInterfaceSrc(val.typ.val) && !isEmptyInterface(val.typ.val): values[fieldIndex] = genValueInterfaceArray(val) case isInterfaceSrc(ft) && !isEmptyInterface(ft): values[fieldIndex] = genValueInterface(val)