Merge pull request #30684 from hashicorp/alisdair/fix-sum-func
functions: Fix sum() of all strings
This commit is contained in:
commit
0bf4112c28
|
@ -527,6 +527,10 @@ var SumFunc = function.New(&function.Spec{
|
||||||
if s.IsNull() {
|
if s.IsNull() {
|
||||||
return cty.NilVal, function.NewArgErrorf(0, "argument must be list, set, or tuple of number values")
|
return cty.NilVal, function.NewArgErrorf(0, "argument must be list, set, or tuple of number values")
|
||||||
}
|
}
|
||||||
|
s, err = convert.Convert(s, cty.Number)
|
||||||
|
if err != nil {
|
||||||
|
return cty.NilVal, function.NewArgErrorf(0, "argument must be list, set, or tuple of number values")
|
||||||
|
}
|
||||||
for _, v := range arg[1:] {
|
for _, v := range arg[1:] {
|
||||||
if v.IsNull() {
|
if v.IsNull() {
|
||||||
return cty.NilVal, function.NewArgErrorf(0, "argument must be list, set, or tuple of number values")
|
return cty.NilVal, function.NewArgErrorf(0, "argument must be list, set, or tuple of number values")
|
||||||
|
|
|
@ -1629,6 +1629,15 @@ func TestSum(t *testing.T) {
|
||||||
cty.NilVal,
|
cty.NilVal,
|
||||||
"can't compute sum of opposing infinities",
|
"can't compute sum of opposing infinities",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
cty.ListVal([]cty.Value{
|
||||||
|
cty.StringVal("1"),
|
||||||
|
cty.StringVal("2"),
|
||||||
|
cty.StringVal("3"),
|
||||||
|
}),
|
||||||
|
cty.NumberIntVal(6),
|
||||||
|
"",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
|
|
Loading…
Reference in New Issue