diff --git a/mapstructure.go b/mapstructure.go index 1f646317..d7ed4473 100644 --- a/mapstructure.go +++ b/mapstructure.go @@ -1163,7 +1163,7 @@ func (d *Decoder) decodeArray(name string, data interface{}, val reflect.Value) valArray := val - if valArray.Comparable() && valArray.Interface() == reflect.Zero(valArray.Type()).Interface() || d.config.ZeroFields { + if isComparable(valArray) && valArray.Interface() == reflect.Zero(valArray.Type()).Interface() || d.config.ZeroFields { // Check input type if dataValKind != reflect.Array && dataValKind != reflect.Slice { if d.config.WeaklyTypedInput { diff --git a/reflect_go1_19.go b/reflect_go1_19.go new file mode 100644 index 00000000..6b8c71ae --- /dev/null +++ b/reflect_go1_19.go @@ -0,0 +1,9 @@ +//go:build !go1.20 + +package mapstructure + +import "reflect" + +func isComparable(v reflect.Value) bool { + return true +} diff --git a/reflect_go1_20.go b/reflect_go1_20.go new file mode 100644 index 00000000..f8255a1b --- /dev/null +++ b/reflect_go1_20.go @@ -0,0 +1,10 @@ +//go:build go1.20 + +package mapstructure + +import "reflect" + +// TODO: remove once we drop support for Go <1.20 +func isComparable(v reflect.Value) bool { + return v.Comparable() +}