Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hclsyntax: Detect and reject invalid nested splat result
Unfortunately two of the weird splat rules we included to mimic Terraform v0.11's bizarre splat behavior interact in a broken way when combined using nested splat expressions: 1. Applying splat to a list or set value always returns a list value, rather than a tuple value, because that allows returning a more precise unknown value type when the source value is unknown. 2. Applying a splat to a scalar value returns a tuple of either zero or one elements, depending on whether the scalar is null. This returns a tuple rather than a list again because that allows returning more precise information in some unknown value cases. When both of these rules are combined using a nested splat -- rule 2 inside rule 1 -- the second rule causes the nested results to have varying types based on the scalar _value_ rather than only on the list element type, which therefore violates the assumption made by rule 1 that because all elements of a list or set have the same type therefore all splat results on those elements must have the same type. This previously caused a crash due to asking cty to construct an invalid list. We'll now handle this as a normal error diagnostic instead of a crash. Ideally we'd make this situation work and generate a valid result of a different type, such as a list of lists rather than an invalid list of different tuple types. However, it's not clear that we can make that change retroactively without breaking existing code, and combining splat expressions in this way seems to be an edge case anyway -- it took many years before someone actually tried this combination and found the bug. Perhaps a future change will find a way to resolve this without an error, but for now we'll compromise on treating this as invalid since we know it wasn't working before anyway but at least this avoids crashing the host program completely.
- Loading branch information