Skip to content

Commit

Permalink
check for typed nulls in flatten func
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Aug 8, 2022
1 parent 834994b commit ee48093
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cty/function/stdlib/collection.go
Expand Up @@ -525,6 +525,11 @@ func flattener(flattenList cty.Value) ([]cty.Value, []cty.ValueMarks, bool) {
if len(flattenListMarks) > 0 {
markses = append(markses, flattenListMarks)
}

if flattenList.IsNull() {
return nil, markses, true
}

if !flattenList.Length().IsKnown() {
// If we don't know the length of what we're flattening then we can't
// predict the length of our result yet either.
Expand Down
11 changes: 11 additions & 0 deletions cty/function/stdlib/collection_test.go
Expand Up @@ -1825,6 +1825,17 @@ func TestFlatten(t *testing.T) {
Want cty.Value
Err string
}{
{
// typed and untyped null args
cty.TupleVal([]cty.Value{
cty.NullVal(cty.DynamicPseudoType),
cty.NullVal(cty.List(cty.DynamicPseudoType)),
cty.NullVal(cty.List(cty.String)),
}),
cty.TupleVal([]cty.Value{cty.NullVal(cty.DynamicPseudoType)}),
"",
},

{ // Empty case is easy
cty.ListValEmpty(cty.String),
cty.EmptyTupleVal,
Expand Down

0 comments on commit ee48093

Please sign in to comment.