lang/funcs: Don't panic if coalescelist gets an unknown list

This commit is contained in:
Martin Atkins 2018-10-15 14:43:02 -07:00
parent db58b88c2d
commit c990c9f36d
2 changed files with 36 additions and 0 deletions

View File

@ -147,6 +147,12 @@ var CoalesceListFunc = function.New(&function.Spec{
vals := make([]cty.Value, 0, len(args))
for _, arg := range args {
if !arg.IsKnown() {
// If we run into an unknown list at some point, we can't
// predict the final result yet. (If there's a known, non-empty
// arg before this then we won't get here.)
return cty.UnknownVal(retType), nil
}
// We already know this will succeed because of the checks in our Type func above
arg, _ = convert.Convert(arg, retType)

View File

@ -355,6 +355,36 @@ func TestCoalesceList(t *testing.T) {
cty.NilVal,
true,
},
{ // unknown list
[]cty.Value{
cty.ListVal([]cty.Value{
cty.StringVal("third"), cty.StringVal("fourth"),
}),
cty.UnknownVal(cty.List(cty.String)),
},
cty.ListVal([]cty.Value{
cty.StringVal("third"), cty.StringVal("fourth"),
}),
false,
},
{ // unknown list
[]cty.Value{
cty.ListValEmpty(cty.String),
cty.UnknownVal(cty.List(cty.String)),
},
cty.UnknownVal(cty.List(cty.String)),
false,
},
{ // unknown list
[]cty.Value{
cty.UnknownVal(cty.List(cty.String)),
cty.ListVal([]cty.Value{
cty.StringVal("third"), cty.StringVal("fourth"),
}),
},
cty.UnknownVal(cty.List(cty.String)),
false,
},
}
for _, test := range tests {