Skip to content

Commit

Permalink
fix: backport comparable check to <1.20
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sagi-Kazar <[email protected]>
  • Loading branch information
sagikazarmark committed Dec 18, 2023
1 parent 58a4c3b commit a6ec181
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mapstructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 9 additions & 0 deletions reflect_go1_19.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !go1.20

package mapstructure

import "reflect"

func isComparable(v reflect.Value) bool {
return true
}
10 changes: 10 additions & 0 deletions reflect_go1_20.go
Original file line number Diff line number Diff line change
@@ -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()
}

0 comments on commit a6ec181

Please sign in to comment.