Skip to content

Commit

Permalink
flatten: null dynamic values are known
Browse files Browse the repository at this point in the history
When flattening a list of arguments, the special case of a `null`
dynamic value should not force the result to be unknown. We do not check
directly for "IsKnown" here, because it is specifically the dynamic type
which will cause `flatten` to become unknown, while unknown values alone
can be preserved preserved.
  • Loading branch information
jbardin committed Jul 6, 2021
1 parent f40c78a commit c2146d8
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cty/function/stdlib/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.Type().Equals(cty.DynamicPseudoType) && !val.IsNull() {
isKnown = false
}

Expand Down
33 changes: 33 additions & 0 deletions cty/function/stdlib/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.UnknownVal(cty.DynamicPseudoType),
cty.TupleVal([]cty.Value{
cty.StringVal("c"),
}),
}),
cty.UnknownVal(cty.DynamicPseudoType),
"",
},
}

for _, test := range tests {
Expand Down

0 comments on commit c2146d8

Please sign in to comment.