diff --git a/mapstructure.go b/mapstructure.go index 7581806a..1f646317 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.Interface() == reflect.Zero(valArray.Type()).Interface() || d.config.ZeroFields { + if valArray.Comparable() && 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/mapstructure_bugs_test.go b/mapstructure_bugs_test.go index 77bb3132..df44b9d9 100644 --- a/mapstructure_bugs_test.go +++ b/mapstructure_bugs_test.go @@ -625,3 +625,19 @@ func TestMapOmitEmptyWithEmptyFieldnameInTag(t *testing.T) { t.Fatalf("fail: %#v", m) } } + +// GH-340: Decoding array of slices causes panic +type HasNonComparableType struct { + NonComparableType [2][]byte +} + +func TestDecode_nonComparableType(t *testing.T) { + decodeTo := &HasNonComparableType{} + expected := [2][]byte{{1, 2}, {3, 4, 5}} + if err := Decode(map[string]interface{}{"NonComparableType": expected}, &decodeTo); err != nil { + t.Fatal(err) + } + if !reflect.DeepEqual(expected, decodeTo.NonComparableType) { + t.Fatalf("fail: %#v", decodeTo.NonComparableType) + } +}