hcldec: A test case for attributes set to cty.DynamicVal with refinements #626
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.
This test case is here to anticipate a possible bug that isn't actually buggy in the current implementation: if an attribute spec is given a non-dynamic type constraint and then refined based on that type constraint then the hcldec implementation must perform the type conversion first and only then attempt to add the refinements.
Another possible variation here would be for the attribute spec to have a dynamic type constraint (
cty.DynamicPseudoType
) and then try to refine its result. That case isn't tested here because that's always an implementation error in the calling application:RefineValueSpec
must be used only in ways that are valid for the full range of types that the nested spec could produce, and there are no refinements that are valid for the full range ofcty.DynamicPseudoType
--cty.DynamicVal
is unrefineable. That situation can and will panic at runtime, alerting the application developer that they've used hcldec incorrectly. There is no way for end-user input to cause this panic if the calling application is written correctly.This doesn't actually change the system behavior. It's a regression test to catch possible regressions under future maintenance. I added this test case after investigating a suspicion raised in #625, in which I found that the system currently behaves correctly in this case but that there was no test case verifying that to be true.
(The key difference between this and the bug in #625 is that
typeexpr
allows specifying type constraints as part of the end-user input -- the type constraint itself is decided dynamically at runtime -- whereas when usinghcldec
the spec should either be fixed at compile time as part of the application or generated from user input in some other place. In the latter case it's the calling application's responsibility to ensure that the dynamically-generated type constraint is valid before using it withhcldec
.)