mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
lang/funcs: Don't panic if coalescelist gets an unknown list
This commit is contained in:
parent
db58b88c2d
commit
c990c9f36d
@ -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)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user