Ensure typed variables with no value still carry type#3464
Merged
crazy-max merged 1 commit intodocker:masterfrom Oct 17, 2025
Merged
Ensure typed variables with no value still carry type#3464crazy-max merged 1 commit intodocker:masterfrom
crazy-max merged 1 commit intodocker:masterfrom
Conversation
A value-less, untyped variable has always been converted to an empty
string. The intention was that value-less, typed variables convert to a
typed null, which was even specified in a code comment, but was never
actually implemented.
This resulted in a null value with a nil type. A value with a nil type
cannot be coerced ("unified") with any other standard types. When this
mismatch occurs, HCL attempts to return a diagnostic error, which in
turn panics as the nil type is literally a nil pointer.
Signed-off-by: Roberto Villarreal <rrjjvv@yahoo.com>
tonistiigi
approved these changes
Oct 14, 2025
crazy-max
approved these changes
Oct 17, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #3463
A value-less, untyped variable has always been converted to an empty string. The intention was that value-less, typed variables convert to a typed null, which was even specified in a code comment, but was never actually implemented.
This resulted in a null value with a nil type. A value with a nil type cannot be coerced ("unified") with any other standard types. When this mismatch occurs, HCL attempts to return a diagnostic error, which in turn panics as the nil type is literally a nil pointer.
There were existing tests that covered value-less, typed variables, but those were centered around ensuring that bake could handle them and didn't alter their value (unlike untyped variables); they treated no value (or explicit null) more as an error condition/edge case and didn't cover intentional uses.
Also, I noticed at some point some JSON-specific tests were added to complement the HCL-specific tests around typing; let me know if this PR should have equivalent JSON tests as well.