Skip to content

Commit

Permalink
fix: detect field names in struct pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
mvertes authored Feb 22, 2020
1 parent 27520f6 commit d8bdc66
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
20 changes: 20 additions & 0 deletions _test/composite7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

type T struct {
name string
}

var tab = []*T{{
name: "foo",
}, {
name: "bar",
}}

func main() {
println(len(tab))
println(tab[0].name)
}

// Output:
// 2
// foo
7 changes: 6 additions & 1 deletion interp/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,12 @@ func isInterface(t *itype) bool {
func isStruct(t *itype) bool {
// Test first for a struct category, because a recursive interpreter struct may be
// represented by an interface{} at reflect level.
return t.cat == structT || t.TypeOf().Kind() == reflect.Struct
if t.cat == structT {
return true
}
rt := t.TypeOf()
k := rt.Kind()
return k == reflect.Struct || (k == reflect.Ptr && rt.Elem().Kind() == reflect.Struct)
}

func isBool(t *itype) bool { return t.TypeOf().Kind() == reflect.Bool }
Expand Down

0 comments on commit d8bdc66

Please sign in to comment.