Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatList stdlib function doesn't handle unknown sequence arguments #1

Closed
apparentlymart opened this issue May 18, 2018 · 1 comment
Labels
bug crash functions/stdlib The "standard library" functions

Comments

@apparentlymart
Copy link
Collaborator

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:

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.

@apparentlymart 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
@apparentlymart apparentlymart added bug functions/stdlib The "standard library" functions crash labels May 18, 2018
@apparentlymart
Copy link
Collaborator Author

This was fixed in b18a157.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug crash functions/stdlib The "standard library" functions
Projects
None yet
Development

No branches or pull requests

1 participant