lang/funcs: Don't panic when distinct called with empty list

This commit is contained in:
Martin Atkins 2019-05-31 07:37:23 -07:00
parent 8118bf8d93
commit 55794eb658
2 changed files with 8 additions and 0 deletions

View File

@ -363,6 +363,9 @@ var DistinctFunc = function.New(&function.Spec{
}
}
if len(list) == 0 {
return cty.ListValEmpty(retType.ElementType()), nil
}
return cty.ListVal(list), nil
},
})

View File

@ -901,6 +901,11 @@ func TestDistinct(t *testing.T) {
}),
false,
},
{
cty.ListValEmpty(cty.String),
cty.ListValEmpty(cty.String),
false,
},
{
cty.ListVal([]cty.Value{
cty.StringVal("a"),