ext/typeexpr: Avoid refinements on dynamic values #625
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
typeexpr
extension 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
hcldec
also requires a determination before callingRefineWith
, but I'm not familiar enough with thehcldec
package, so I haven't included it here.hcl/hcldec/spec.go
Line 1643 in a9f8d65