Skip to content

Commit

Permalink
function/stdlib: flatten result is entirely unknown if anything has u…
Browse files Browse the repository at this point in the history
…nknown type
  • Loading branch information
jbardin committed May 6, 2021
1 parent a11e513 commit e789782
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cty/function/stdlib/collection.go
Expand Up @@ -530,6 +530,12 @@ func flattener(flattenList cty.Value) ([]cty.Value, []cty.ValueMarks, bool) {
// predict the length of our result yet either.
return nil, markses, false
}
// Any dynamic types could result in more collection that need to be
// flattened, so the type cannot be known.
if flattenList.Type().HasDynamicTypes() {
return nil, markses, false
}

out := make([]cty.Value, 0)
isKnown := true
for it := flattenList.ElementIterator(); it.Next(); {
Expand Down
53 changes: 53 additions & 0 deletions cty/function/stdlib/collection_test.go
Expand Up @@ -1928,6 +1928,59 @@ func TestFlatten(t *testing.T) {
cty.EmptyTupleVal.Mark("a"),
"",
},
{
cty.ListValEmpty(cty.Number),
cty.EmptyTupleVal,
"",
},
{
cty.ListVal([]cty.Value{
cty.DynamicVal,
}),
cty.DynamicVal,
"",
},
{
cty.TupleVal([]cty.Value{
cty.ListVal([]cty.Value{
cty.ListVal([]cty.Value{
cty.DynamicVal,
}),
}),
cty.ListVal([]cty.Value{
cty.ListVal([]cty.Value{
cty.DynamicVal,
}).Mark("marked"),
}),
}),
cty.DynamicVal,
"",
},
{
cty.TupleVal([]cty.Value{
cty.StringVal("a"),
cty.ListVal([]cty.Value{
cty.StringVal("b"),
}),
cty.TupleVal([]cty.Value{
cty.ListVal([]cty.Value{
cty.StringVal("c"),
}),
cty.ListVal([]cty.Value{
cty.StringVal("d"),
cty.StringVal("e"),
}),
}),
}),
cty.TupleVal([]cty.Value{
cty.StringVal("a"),
cty.StringVal("b"),
cty.StringVal("c"),
cty.StringVal("d"),
cty.StringVal("e"),
}),
"",
},
}

for _, test := range tests {
Expand Down

0 comments on commit e789782

Please sign in to comment.