From fa4223fb48d983ea7db0793ce28faf3be1b74605 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 10 Aug 2021 17:19:56 -0400 Subject: [PATCH] formatlist: a DynamicVal arg may be a list When formatlist encounters a DynamicVal argument, it must return an unknown result, as it cannot determine if that will be a single value argument resulting in an unknown string, or a list to be formatted into an unknown number of strings. --- cty/function/stdlib/format.go | 2 ++ cty/function/stdlib/format_test.go | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/cty/function/stdlib/format.go b/cty/function/stdlib/format.go index 63881f58..8b177589 100644 --- a/cty/function/stdlib/format.go +++ b/cty/function/stdlib/format.go @@ -114,6 +114,8 @@ var FormatListFunc = function.New(&function.Spec{ continue } iterators[i] = arg.ElementIterator() + case arg == cty.DynamicVal: + unknowns[i] = true default: singleVals[i] = arg } diff --git a/cty/function/stdlib/format_test.go b/cty/function/stdlib/format_test.go index 2a8db6ca..aad73a8f 100644 --- a/cty/function/stdlib/format_test.go +++ b/cty/function/stdlib/format_test.go @@ -836,6 +836,15 @@ func TestFormatList(t *testing.T) { cty.UnknownVal(cty.List(cty.String)), ``, }, + 23: { + cty.StringVal("%v"), + []cty.Value{cty.DynamicVal}, + // The current Function implementation will default to DynamicVal + // if AllowUnknown is true, even though this function has a static + // return type + cty.DynamicVal, + ``, + }, } for i, test := range tests {