Skip to content

Commit 8072955

Browse files
authored
fix(args): none arg set slice ptr to an empty slice (#2752)
1 parent 0c3d8ec commit 8072955

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

internal/args/unmarshal.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,11 @@ func set(dest reflect.Value, argNameWords []string, value string) error {
240240
// - dest is a pointer to a slice
241241
// - there is no more argNameWords left
242242
// - value == none
243-
// we let the slice empty and return
243+
// slice ptr was allocated
244+
// we allocate the empty slice and return
244245
if dest.Elem().Kind() == reflect.Slice && len(argNameWords) == 0 && value == emptySliceValue {
246+
sliceDest := dest.Elem()
247+
sliceDest.Set(reflect.MakeSlice(sliceDest.Type(), 0, 0))
245248
return nil
246249
}
247250

internal/args/unmarshal_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func TestUnmarshalStruct(t *testing.T) {
202202
},
203203
expected: &Slice{
204204
Strings: []string(nil),
205-
SlicePtr: scw.StringsPtr(nil),
205+
SlicePtr: scw.StringsPtr([]string{}),
206206
StringsPtr: []*string(nil),
207207
},
208208
}))

0 commit comments

Comments
 (0)