Skip to content

Commit 9e63be1

Browse files
author
Patrick Pichler
committed
Always use interface value when retrieving field values
Instead of trying to specially handle zero field values, the code instead depends on the values to be properly handled further down the stack.
1 parent dc9c0d2 commit 9e63be1

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

ext/native.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (tp *nativeTypeProvider) FindStructFieldType(typeName, fieldName string) (*
279279
GetFrom: func(obj any) (any, error) {
280280
refVal := reflect.Indirect(reflect.ValueOf(obj))
281281
refField := valueFieldByName(tp.options.parseStructTags, refVal, fieldName)
282-
return getFieldValue(tp, refField), nil
282+
return refField.Interface(), nil
283283
},
284284
}, true
285285
}
@@ -704,29 +704,7 @@ func (t *nativeType) hasField(fieldName string) (reflect.StructField, bool) {
704704
}
705705

706706
func adaptFieldValue(adapter types.Adapter, refField reflect.Value) ref.Val {
707-
return adapter.NativeToValue(getFieldValue(adapter, refField))
708-
}
709-
710-
func getFieldValue(adapter types.Adapter, refField reflect.Value) any {
711-
if refField.IsZero() {
712-
switch refField.Kind() {
713-
case reflect.Array, reflect.Slice:
714-
if refField.Type().Elem() == reflect.TypeOf(byte(0)) {
715-
return refField.Interface()
716-
}
717-
return types.NewDynamicList(adapter, []ref.Val{})
718-
case reflect.Map:
719-
return types.NewDynamicMap(adapter, map[ref.Val]ref.Val{})
720-
case reflect.Struct:
721-
if refField.Type() == timestampType {
722-
return types.Timestamp{Time: time.Unix(0, 0)}
723-
}
724-
return reflect.New(refField.Type()).Elem().Interface()
725-
case reflect.Pointer:
726-
return reflect.New(refField.Type().Elem()).Interface()
727-
}
728-
}
729-
return refField.Interface()
707+
return adapter.NativeToValue(refField.Interface())
730708
}
731709

732710
func simplePkgAlias(pkgPath string) string {

0 commit comments

Comments
 (0)