Skip to content

Commit

Permalink
lang/funcs: Don't panic when distinct called with empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
apparentlymart committed May 31, 2019
1 parent 8118bf8 commit 55794eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lang/funcs/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
})
Expand Down
5 changes: 5 additions & 0 deletions lang/funcs/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down

0 comments on commit 55794eb

Please sign in to comment.