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 <mark.sagikazar@gmail.com>
  • Loading branch information
sagikazarmark committed Dec 18, 2023
1 parent 58a4c3b commit 7cf9124
Show file tree
Hide file tree
Showing 3 changed files with 17 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
7 changes: 7 additions & 0 deletions reflect.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package mapstructure

import "reflect"

func isComparable(v reflect.Value) bool {

Check failure on line 5 in reflect.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

other declaration of isComparable

Check failure on line 5 in reflect.go

View workflow job for this annotation

GitHub Actions / Test (1.18)

other declaration of isComparable

Check failure on line 5 in reflect.go

View workflow job for this annotation

GitHub Actions / Test (1.19)

other declaration of isComparable
return v.Comparable()

Check failure on line 6 in reflect.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

v.Comparable undefined (type reflect.Value has no field or method Comparable)

Check failure on line 6 in reflect.go

View workflow job for this annotation

GitHub Actions / Test (1.18)

v.Comparable undefined (type reflect.Value has no field or method Comparable)

Check failure on line 6 in reflect.go

View workflow job for this annotation

GitHub Actions / Test (1.19)

v.Comparable undefined (type reflect.Value has no field or method Comparable)
}
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 {

Check failure on line 7 in reflect_go1_19.go

View workflow job for this annotation

GitHub Actions / test (1.18.x, ubuntu-latest)

isComparable redeclared in this block

Check failure on line 7 in reflect_go1_19.go

View workflow job for this annotation

GitHub Actions / Test (1.18)

isComparable redeclared in this block

Check failure on line 7 in reflect_go1_19.go

View workflow job for this annotation

GitHub Actions / Test (1.19)

isComparable redeclared in this block
return true
}

0 comments on commit 7cf9124

Please sign in to comment.