ext/typeexpr: Avoid refinements on dynamic values#625
ext/typeexpr: Avoid refinements on dynamic values#625apparentlymart merged 1 commit intohashicorp:mainfrom
Conversation
|
Thanks for finding and fixing this! Having encountered variants of this bug a few times now I'm considering (wearing my other hat as Therefore I'm going to merge this to fix the direct bug as reported and wait to see how many more examples of these situations we'll find before making a decision about whether to change I think that Thanks again! |
See also #590
See also terraform-linters/tflint#1831
Refinements introduced in #590 has a restriction that it cannot refine unknown values of unknown types (
cty.DynamicVal). Refining dynamic values causes a panic.https://github.com/zclconf/go-cty/blob/v1.13.3/cty/unknown_refinement.go#L46-L47
The
typeexprextension may refine optional attribute as non-null, but dynamic values are not taken into account here, causing a panic.This PR fixes the panic by avoiding refinement when the value type is
cty.DynamicPseudoType. This is the same approach in the splat operator, so it's probably reasonable to do the same here.hcl/hclsyntax/expression.go
Lines 1735 to 1737 in a9f8d65
As a side note, I reviewed #590 again, and this is probably the only place we should consider dynamic values. Perhaps the
hcldecalso requires a determination before callingRefineWith, but I'm not familiar enough with thehcldecpackage, so I haven't included it here.hcl/hcldec/spec.go
Line 1643 in a9f8d65