Skip to content

Commit

Permalink
function/stdlib: Don't panic if one of the setproduct arguments is an…
Browse files Browse the repository at this point in the history
… empty collection

Due to some incorrect marking in the empty result codepaths, this was causing panics.
When applying a ValueMarks we must use WithMarks, not Mark.
  • Loading branch information
mantoine96 committed Apr 30, 2021
1 parent 0f407f9 commit d3698c0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
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

0 comments on commit d3698c0

Please sign in to comment.