Skip to content

Commit

Permalink
function: concat might need the length of a marked value during type …
Browse files Browse the repository at this point in the history
…checking

If concat is building a tuple type, it will need to check the length of
the arguments, which requires unmarking the values.
  • Loading branch information
jbardin authored Jun 10, 2021
1 parent f40c78a commit 4e5310f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cty/function/stdlib/sequence.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ var ConcatFunc = function.New(&function.Spec{

etys := make([]cty.Type, 0, len(args))
for i, val := range args {
// Discard marks for nested values, as we only need to handle types
// and lengths.
val, _ := val.UnmarkDeep()

ety := val.Type()
switch {
case ety.IsTupleType():
Expand Down
26 changes: 26 additions & 0 deletions cty/function/stdlib/sequence_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,32 @@ func TestConcat(t *testing.T) {
cty.NumberIntVal(3),
}).Mark("a"),
},
{
[]cty.Value{
cty.ListValEmpty(cty.DynamicPseudoType).Mark("a"),
cty.ListVal([]cty.Value{
cty.NumberIntVal(2).Mark("b"),
cty.NumberIntVal(3),
}).Mark("c"),
},
cty.ListVal([]cty.Value{
cty.NumberIntVal(2).Mark("b"),
cty.NumberIntVal(3),
}).WithMarks(cty.NewValueMarks("a", "c")),
},
{
[]cty.Value{
cty.ListValEmpty(cty.DynamicPseudoType).Mark("a"),
cty.TupleVal([]cty.Value{
cty.NumberIntVal(2).Mark("b"),
cty.NumberIntVal(3),
}).Mark("c"),
},
cty.TupleVal([]cty.Value{
cty.NumberIntVal(2).Mark("b"),
cty.NumberIntVal(3),
}).WithMarks(cty.NewValueMarks("a", "c")),
},
{
[]cty.Value{
cty.ListVal([]cty.Value{
Expand Down

0 comments on commit 4e5310f

Please sign in to comment.