Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

flatten must return unknown with dynamic vals #106

Merged
merged 1 commit into from May 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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