Skip to content

Commit

Permalink
interp: fix populating array of interfaces
Browse files Browse the repository at this point in the history
Fixes #1308.
  • Loading branch information
mvertes authored Nov 9, 2021
1 parent 348e713 commit 9214806
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions _test/issue-1308.go
Original file line number Diff line number Diff line change
@@ -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}]
2 changes: 1 addition & 1 deletion interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 9214806

Please sign in to comment.