Skip to content

Commit

Permalink
Merge pull request #146 from kkHAIKE/array_set_fix
Browse files Browse the repository at this point in the history
fix Array case bug for Set
  • Loading branch information
thoas authored Mar 16, 2022
2 parents 38b2794 + b15e3d5 commit dfe9213
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion assign.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func set(inValue reflect.Value, setValue reflect.Value, parts []string) error {
}
inValue = fValue
i++
case reflect.Slice | reflect.Array:
case reflect.Slice, reflect.Array:
// set all its elements
length := inValue.Len()
for j := 0; j < length; j++ {
Expand Down
7 changes: 7 additions & 0 deletions assign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,13 @@ func TestSet_SlicePassDirectly(t *testing.T) {
SetVal: "val",
Expected: []*Bar{{Name: "val"}, {Name: "val"}},
},
// Array of ptr
{
Original: [2]*Bar{{Name: "a"}, {Name: "b"}},
Path: "Name",
SetVal: "val",
Expected: [2]*Bar{{Name: "val"}, {Name: "val"}},
},
// slice of struct
{
Original: []Bar{{Name: "a"}, {Name: "b"}},
Expand Down

0 comments on commit dfe9213

Please sign in to comment.