@@ -92,9 +92,9 @@ func (d *Decoder) Decode(dst interface{}, src map[string][]string) error {
9292 return nil
9393}
9494
95- //setDefaults sets the default values when the `default` tag is specified,
96- //default is supported on basic/primitive types and their pointers,
97- //nested structs can also have default tags
95+ // setDefaults sets the default values when the `default` tag is specified,
96+ // default is supported on basic/primitive types and their pointers,
97+ // nested structs can also have default tags
9898func (d * Decoder ) setDefaults (t reflect.Type , v reflect.Value ) MultiError {
9999 struc := d .cache .get (t )
100100 if struc == nil {
@@ -130,9 +130,12 @@ func (d *Decoder) setDefaults(t reflect.Type, v reflect.Value) MultiError {
130130 defaultSlice := reflect .MakeSlice (f .typ , 0 , cap (vals ))
131131 for _ , val := range vals {
132132 //this check is to handle if the wrong value is provided
133- if convertedVal := builtinConverters [f .typ .Elem ().Kind ()](val ); convertedVal .IsValid () {
134- defaultSlice = reflect .Append (defaultSlice , convertedVal )
133+ convertedVal := builtinConverters [f .typ .Elem ().Kind ()](val )
134+ if ! convertedVal .IsValid () {
135+ errs .merge (MultiError {"default-" + f .name : errors .New ("some elements in the slice are of a different type." )})
136+ break
135137 }
138+ defaultSlice = reflect .Append (defaultSlice , convertedVal )
136139 }
137140 vCurrent .Set (defaultSlice )
138141 } else if f .typ .Kind () == reflect .Ptr {
0 commit comments