Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stdlib: Conversion functions can accept unknown-typed nulls
This is one of those confusing situations where the multiple subtly-different meanings of cty.DynamicPseudoType meet: - The "Type" field specifies a target type that the argument must be converted to before calling the function, and so cty.DynamicPseudoType here essentially means "don't do any pre-conversion at all". - However, that means that the value given as an argument might be a null or unknown value with a type constraint. In that position, cty.DynamicPseudoType represents "we don't yet know the type", which not all functions are equipped to deal with and so those that are must opt-in with AllowDynamicPseudoType: true. Without declaring AllowDynamicPseudoType, the general function handling code will just skip calling the function at all when the argument doesn't yet have a known type, returning an unknown value of an unknown type to represent that the function's result cannot be known until the argument's type has become known. However, type conversion functions can safely accept values of unknown type, because they are just thin wrappers around package convert which already deal with that situation automatically. The conversion functions should set AllowDynamicType: true so that package convert can be the one to deal with the situation, and can thus convert a null value of unknown type into a null value of the target type (since null-to-null conversions are always allowed).
- Loading branch information