From 4e5310ff50fce1202bed3a3a9e350e0adafa4393 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 10 Jun 2021 12:02:47 -0400 Subject: [PATCH] function: concat might need the length of a marked value during type checking If concat is building a tuple type, it will need to check the length of the arguments, which requires unmarking the values. --- cty/function/stdlib/sequence.go | 4 ++++ cty/function/stdlib/sequence_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/cty/function/stdlib/sequence.go b/cty/function/stdlib/sequence.go index 8cfed57f..6a6f66b3 100644 --- a/cty/function/stdlib/sequence.go +++ b/cty/function/stdlib/sequence.go @@ -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(): diff --git a/cty/function/stdlib/sequence_test.go b/cty/function/stdlib/sequence_test.go index 483ea97d..d2f58fda 100644 --- a/cty/function/stdlib/sequence_test.go +++ b/cty/function/stdlib/sequence_test.go @@ -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{