Skip to content

Commit

Permalink
formatlist: a DynamicVal arg may be a list
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jbardin authored and apparentlymart committed Aug 18, 2021
1 parent b537cd6 commit fa4223f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cty/function/stdlib/format.go
Expand Up @@ -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
}
Expand Down
9 changes: 9 additions & 0 deletions cty/function/stdlib/format_test.go
Expand Up @@ -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 {
Expand Down

0 comments on commit fa4223f

Please sign in to comment.