Skip to content

Ensure typed variables with no value still carry type#3464

Merged
crazy-max merged 1 commit intodocker:masterfrom
rrjjvv:typed-vars-as-null
Oct 17, 2025
Merged

Ensure typed variables with no value still carry type#3464
crazy-max merged 1 commit intodocker:masterfrom
rrjjvv:typed-vars-as-null

Conversation

@rrjjvv
Copy link
Contributor

@rrjjvv rrjjvv commented Oct 11, 2025

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.

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>
@crazy-max crazy-max merged commit 40828e6 into docker:master Oct 17, 2025
139 checks passed
@rrjjvv rrjjvv deleted the typed-vars-as-null branch October 17, 2025 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bake: panic when using undefined typed variables as null

4 participants