From 55794eb6583608ecf15344f101d1e129ccffc3f4 Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Fri, 31 May 2019 07:37:23 -0700 Subject: [PATCH] lang/funcs: Don't panic when distinct called with empty list --- lang/funcs/collection.go | 3 +++ lang/funcs/collection_test.go | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/lang/funcs/collection.go b/lang/funcs/collection.go index 71b7a8466..1257895e3 100644 --- a/lang/funcs/collection.go +++ b/lang/funcs/collection.go @@ -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 }, }) diff --git a/lang/funcs/collection_test.go b/lang/funcs/collection_test.go index d1a543797..e408d385b 100644 --- a/lang/funcs/collection_test.go +++ b/lang/funcs/collection_test.go @@ -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"),