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 authored and apparentlymart committed Aug 22, 2022
1 parent 834994b commit fefcf9f
Show file tree
Hide file tree
Showing 2 changed files with 53 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
48 changes: 48 additions & 0 deletions cty/function/stdlib/collection_test.go
Expand Up @@ -2064,6 +2064,54 @@ func TestFlatten(t *testing.T) {
cty.UnknownVal(cty.DynamicPseudoType),
"",
},
{
// null of an unknown type
cty.TupleVal([]cty.Value{
cty.NullVal(cty.DynamicPseudoType),
cty.True,
}),
cty.TupleVal([]cty.Value{
cty.NullVal(cty.DynamicPseudoType),
cty.True,
}),
"",
},
{
// null of a string type
cty.TupleVal([]cty.Value{
cty.NullVal(cty.String),
cty.True,
}),
cty.TupleVal([]cty.Value{
cty.NullVal(cty.String),
cty.True,
}),
"",
},
{
// null of a list type
cty.TupleVal([]cty.Value{
cty.NullVal(cty.List(cty.String)),
cty.True,
}),
cty.TupleVal([]cty.Value{
cty.NullVal(cty.List(cty.String)),
cty.True,
}),
"",
},
{
// null of a tuple type
cty.TupleVal([]cty.Value{
cty.NullVal(cty.EmptyTuple),
cty.True,
}),
cty.TupleVal([]cty.Value{
cty.NullVal(cty.EmptyTuple),
cty.True,
}),
"",
},
}

for _, test := range tests {
Expand Down

0 comments on commit fefcf9f

Please sign in to comment.