lang/funcs: Permit object types in the "length" function
The implementation already allowed this, so this was just an oversight in the type checking function. This fixes #19278.
This commit is contained in:
parent
c795302ab2
commit
8f578c365f
|
@ -87,7 +87,7 @@ var LengthFunc = function.New(&function.Spec{
|
|||
Type: func(args []cty.Value) (cty.Type, error) {
|
||||
collTy := args[0].Type()
|
||||
switch {
|
||||
case collTy == cty.String || collTy.IsTupleType() || collTy.IsListType() || collTy.IsMapType() || collTy.IsSetType() || collTy == cty.DynamicPseudoType:
|
||||
case collTy == cty.String || collTy.IsTupleType() || collTy.IsObjectType() || collTy.IsListType() || collTy.IsMapType() || collTy.IsSetType() || collTy == cty.DynamicPseudoType:
|
||||
return cty.Number, nil
|
||||
default:
|
||||
return cty.Number, fmt.Errorf("argument must be a string, a collection type, or a structural type")
|
||||
|
|
|
@ -163,10 +163,26 @@ func TestLength(t *testing.T) {
|
|||
cty.EmptyTupleVal,
|
||||
cty.NumberIntVal(0),
|
||||
},
|
||||
{
|
||||
cty.UnknownVal(cty.EmptyTuple),
|
||||
cty.NumberIntVal(0),
|
||||
},
|
||||
{
|
||||
cty.TupleVal([]cty.Value{cty.True}),
|
||||
cty.NumberIntVal(1),
|
||||
},
|
||||
{
|
||||
cty.EmptyObjectVal,
|
||||
cty.NumberIntVal(0),
|
||||
},
|
||||
{
|
||||
cty.UnknownVal(cty.EmptyObject),
|
||||
cty.NumberIntVal(0),
|
||||
},
|
||||
{
|
||||
cty.ObjectVal(map[string]cty.Value{"true": cty.True}),
|
||||
cty.NumberIntVal(1),
|
||||
},
|
||||
{
|
||||
cty.UnknownVal(cty.List(cty.Bool)),
|
||||
cty.UnknownVal(cty.Number),
|
||||
|
|
Loading…
Reference in New Issue