From 1712101b2a609156da53405bbf94b0ff7d011e36 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 6 Jul 2021 19:08:27 -0400 Subject: [PATCH] function/stdlib: flatten no longer treats null values as unknown --- cty/function/stdlib/collection.go | 2 +- cty/function/stdlib/collection_test.go | 33 ++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/cty/function/stdlib/collection.go b/cty/function/stdlib/collection.go index f50f196e..279a20ee 100644 --- a/cty/function/stdlib/collection.go +++ b/cty/function/stdlib/collection.go @@ -538,7 +538,7 @@ func flattener(flattenList cty.Value) ([]cty.Value, []cty.ValueMarks, bool) { // Any dynamic types could result in more collections that need to be // flattened, so the type cannot be known. - if val.Type().Equals(cty.DynamicPseudoType) { + if val == cty.DynamicVal { isKnown = false } diff --git a/cty/function/stdlib/collection_test.go b/cty/function/stdlib/collection_test.go index cfafb4af..0d5d5e83 100644 --- a/cty/function/stdlib/collection_test.go +++ b/cty/function/stdlib/collection_test.go @@ -2031,6 +2031,39 @@ func TestFlatten(t *testing.T) { }), "", }, + { + cty.TupleVal([]cty.Value{ + cty.TupleVal([]cty.Value{ + cty.StringVal("a"), + cty.StringVal("b"), + }), + cty.NullVal(cty.DynamicPseudoType), + cty.TupleVal([]cty.Value{ + cty.StringVal("c"), + }), + }), + cty.TupleVal([]cty.Value{ + cty.StringVal("a"), + cty.StringVal("b"), + cty.NullVal(cty.DynamicPseudoType), + cty.StringVal("c"), + }), + "", + }, + { + cty.TupleVal([]cty.Value{ + cty.TupleVal([]cty.Value{ + cty.StringVal("a"), + cty.StringVal("b"), + }), + cty.DynamicVal, + cty.TupleVal([]cty.Value{ + cty.StringVal("c"), + }), + }), + cty.UnknownVal(cty.DynamicPseudoType), + "", + }, } for _, test := range tests {