Skip to content

Commit f96a18c

Browse files
committed
cue: decode empty list as empty slice instead of slice-typed nil
Signed-off-by: Artem V. Navrotskiy <[email protected]>
1 parent 24e8d56 commit f96a18c

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

cue/decode.go

+3
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,9 @@ func (d *decoder) interfaceValue(v Value) (x interface{}) {
280280
for list.Next() {
281281
a = append(a, d.interfaceValue(list.Value()))
282282
}
283+
if a == nil {
284+
a = []interface{}{}
285+
}
283286
x = a
284287

285288
case StructKind:

cue/decode_test.go

+4
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ func TestDecode(t *testing.T) {
231231
`,
232232
dst: &S{},
233233
err: "Decode: x: cannot use value 1 (type int) as (string|bytes)",
234+
}, {
235+
value: `[]`,
236+
dst: new(interface{}),
237+
want: []interface{}{},
234238
}}
235239
for _, tc := range testCases {
236240
t.Run(tc.value, func(t *testing.T) {

0 commit comments

Comments
 (0)