From 5166a5b02171faaba6910717b0d83d40406e3bf7 Mon Sep 17 00:00:00 2001 From: Eddy Reyes Date: Wed, 13 Apr 2016 02:08:25 -0500 Subject: [PATCH] dancannon/gorethink#301 Do not attempt to traverse the fields of an anonymous pseudo-type (i.e. a time.Time) --- encoding/cache.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/encoding/cache.go b/encoding/cache.go index 041497a1..bffb4cdc 100644 --- a/encoding/cache.go +++ b/encoding/cache.go @@ -6,6 +6,7 @@ import ( "reflect" "sort" "sync" + "time" ) // A field represents a single field found in a struct. @@ -131,7 +132,7 @@ func typeFields(t reflect.Type) []field { } // Record found field and index sequence. - if name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct { + if name != "" || !sf.Anonymous || ft.Kind() != reflect.Struct || isPseudoType(ft) { tagged := name != "" if name == "" { name = sf.Name @@ -200,6 +201,10 @@ func typeFields(t reflect.Type) []field { return fields } +func isPseudoType(t reflect.Type) bool { + return t == reflect.TypeOf(time.Time{}) +} + // dominantField looks through the fields, all of which are known to // have the same name, to find the single field that dominates the // others using Go's embedding rules, modified by the presence of