Skip to content

Commit 2c130b7

Browse files
committed
Merge pull request #304 from ereyes01/anon_time
Do not attempt to traverse the fields of an anonymous pseudo-type
2 parents e75533a + 804c10a commit 2c130b7

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

encoding/cache.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"reflect"
77
"sort"
88
"sync"
9+
"time"
910
)
1011

1112
// A field represents a single field found in a struct.
@@ -131,7 +132,7 @@ func typeFields(t reflect.Type) []field {
131132
}
132133

133134
// Record found field and index sequence.
134-
if name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct {
135+
if name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct || isPseudoType(ft) {
135136
tagged := name != ""
136137
if name == "" {
137138
name = sf.Name
@@ -200,6 +201,10 @@ func typeFields(t reflect.Type) []field {
200201
return fields
201202
}
202203

204+
func isPseudoType(t reflect.Type) bool {
205+
return t == reflect.TypeOf(time.Time{})
206+
}
207+
203208
// dominantField looks through the fields, all of which are known to
204209
// have the same name, to find the single field that dominates the
205210
// others using Go's embedding rules, modified by the presence of

0 commit comments

Comments
 (0)