You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
case (argTy.IsListType() ||argTy.IsSetType() ||argTy.IsTupleType()) &&!arg.IsNull():
thisLen:=arg.LengthInt()
This doesn't account for the situation where the value is of a sequence type but it is unknown, and so the LengthInt call here will panic in that case.
This must be handled slightly differently for lists and sets vs. tuples:
For lists and sets, an unknown value has an unknown length, and so the overall result of this function can't be anything other than cty.UnknownVal(cty.List(cty.String)) because the length of the result can't be predicted.
For tuples, the length of the sequence is part of the tuple type and so we can predict the length even if the exact value isn't known. However, we still can't iterate over an unknown tuple, and so the result in this case would be a known list of strings whose elements are themselves all unknown string values.
Given that the two above cases can mix, probably the best solution here is to just have a flag that we set for each case during iteration and then handle them both just before the iterLen == 0 check that follows, giving preference to the list/set outcome if both lists and tuples are present.
The text was updated successfully, but these errors were encountered:
apparentlymart
changed the title
formatlist stdlib function doesn't handle unknown sequence arguments
FormatList stdlib function doesn't handle unknown sequence arguments
May 18, 2018
The following
case
is used when testing each of the arguments to see if it is a sequence that we'll iterate over, and to check its length:go-cty/cty/function/stdlib/format.go
Lines 86 to 87 in d006e45
This doesn't account for the situation where the value is of a sequence type but it is unknown, and so the
LengthInt
call here will panic in that case.This must be handled slightly differently for lists and sets vs. tuples:
cty.UnknownVal(cty.List(cty.String))
because the length of the result can't be predicted.Given that the two above cases can mix, probably the best solution here is to just have a flag that we set for each case during iteration and then handle them both just before the
iterLen == 0
check that follows, giving preference to the list/set outcome if both lists and tuples are present.The text was updated successfully, but these errors were encountered: