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

Fix panic in setproduct when one of the arguments is an empty list #103

Merged
merged 3 commits into from
Apr 30, 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
4 changes: 2 additions & 2 deletions cty/function/stdlib/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,9 @@ var SetProductFunc = function.New(&function.Spec{
// If any of the arguments was an empty collection then our result
// is also an empty collection, which we'll short-circuit here.
if retType.IsListType() {
return cty.ListValEmpty(ety).Mark(retMarks), nil
return cty.ListValEmpty(ety).WithMarks(retMarks), nil
}
return cty.SetValEmpty(ety).Mark(retMarks), nil
return cty.SetValEmpty(ety).WithMarks(retMarks), nil
}

subEtys := ety.TupleElementTypes()
Expand Down
38 changes: 38 additions & 0 deletions cty/function/stdlib/collection_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,44 @@ func TestSetproduct(t *testing.T) {
cty.NilVal,
`at least two arguments are required`,
},
{
[]cty.Value{
cty.ListValEmpty(cty.EmptyObject),
cty.ListVal([]cty.Value{
cty.StringVal("quick"),
cty.StringVal("fox"),
}),
},
cty.ListValEmpty(cty.Tuple([]cty.Type{cty.EmptyObject, cty.String})),
``,
},
{
[]cty.Value{
cty.SetValEmpty(cty.EmptyObject),
cty.SetVal([]cty.Value{
cty.StringVal("quick"),
cty.StringVal("fox"),
}),
},
cty.SetValEmpty(cty.Tuple([]cty.Type{cty.EmptyObject, cty.String})),
``,
},
{
[]cty.Value{
cty.ListValEmpty(cty.EmptyObject),
cty.ListValEmpty(cty.EmptyObject),
},
cty.ListValEmpty(cty.Tuple([]cty.Type{cty.EmptyObject, cty.EmptyObject})),
``,
},
{
[]cty.Value{
cty.SetValEmpty(cty.EmptyObject),
cty.SetValEmpty(cty.EmptyObject),
},
cty.SetValEmpty(cty.Tuple([]cty.Type{cty.EmptyObject, cty.EmptyObject})),
``,
},
{
[]cty.Value{
cty.ListVal([]cty.Value{cty.ListValEmpty(cty.String)}),
Expand Down