diff --git a/_test/struct45.go b/_test/struct45.go new file mode 100644 index 00000000..9c66dc33 --- /dev/null +++ b/_test/struct45.go @@ -0,0 +1,17 @@ +package main + +type T struct { + b bool +} + +type T1 struct { + T +} + +func main() { + t := &T1{} + t.b = true + println(t.b) +} + +// Output: true diff --git a/interp/type.go b/interp/type.go index 012be638..1efd5bba 100644 --- a/interp/type.go +++ b/interp/type.go @@ -857,7 +857,8 @@ func (t *itype) zero() (v reflect.Value, err error) { // fieldIndex returns the field index from name in a struct, or -1 if not found func (t *itype) fieldIndex(name string) int { - if t.cat == ptrT { + switch t.cat { + case aliasT, ptrT: return t.val.fieldIndex(name) } for i, field := range t.field { @@ -882,6 +883,10 @@ func (t *itype) fieldSeq(seq []int) *itype { // lookupField returns a list of indices, i.e. a path to access a field in a struct object func (t *itype) lookupField(name string) []int { + switch t.cat { + case aliasT, ptrT: + return t.val.lookupField(name) + } if fi := t.fieldIndex(name); fi >= 0 { return []int{fi} }