Previously the type-selection codepath for an input tuple referred
unconditionally to the start and end index values. In the Type callback,
only the types of the arguments are guaranteed to be known, so any access
to the values must be guarded with an .IsKnown check, or else the function
will not short-circuit properly when an unknown value is passed.
Now we will check the start and end indices are in range when we have
enough information to do so, but we'll return an approximate result if
either is unknown.
@ -1064,11 +1064,11 @@ var SliceFunc = function.New(&function.Spec{
Type:cty.DynamicPseudoType,
},
{
Name:"startIndex",
Name:"start_index",
Type:cty.Number,
},
{
Name:"endIndex",
Name:"end_index",
Type:cty.Number,
},
},
@ -1076,25 +1076,39 @@ var SliceFunc = function.New(&function.Spec{
arg:=args[0]
argTy:=arg.Type()
ifargTy.IsSetType(){
returncty.NilType,function.NewArgErrorf(0,"cannot slice a set, because its elements do not have indices; use the tolist function to force conversion to list if the ordering of the result is not important")
}
if!argTy.IsListType()&&!argTy.IsTupleType(){
returncty.NilType,errors.New("cannot slice a set, because its elements do not have indices; use the tolist function to force conversion to list if the ordering of the result is not important")
returncty.NilType,function.NewArgErrorf(0,"must be a list or tuple value")