adapter-v2: sync optional object defaults from main#169
Merged
Conversation
…#168) * workflow: support optional() with defaults in object type constraints Replaces typeexpr.Type() with typeexpr.TypeConstraintWithDefaults() when parsing variable, shared_variable, and output type expressions. This enables the Terraform-style optional attribute modifier with default values: type = object({ a = optional(string, "default_a") b = optional(number, 42) }) Type-level defaults are stored on the compiled node (VariableNode, SharedVariableNode, OutputNode) and applied before cty type conversion at both compile time (for foldable values) and runtime (for output expressions evaluated against the final run state). Compile-time behavioral changes: - variable default = {} now resolves missing optional fields from the type. - shared_variable initial values are coerced via convert.Convert (replacing strict type equality) so optional-attribute objects match correctly. - output foldable values get defaults applied before compile-time type check. Runtime behavioral changes: - evalRunOutputs and evalRunOutputsAsValues apply defaults before converting output expressions to their declared types. Tests cover: - variable with object optional defaults - shared_variable with object optional defaults - output with object optional defaults - single-arg optional (no default value) still parses and resolves to null * run make spec-gen --------- Co-authored-by: Dave Sanderson <dave@brokenbots.net>
brokenbot
approved these changes
May 26, 2026
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.
Cherry-picks PR #168 (optional object defaults) from main onto the adapter-v2 feature branch.
This brings the single delta that main has beyond what adapter-v2 already contains:
typeexpr.TypeConstraintWithDefaults()support foroptional(string, "default")inside object type constraints on variable, shared_variable, and output blocks.Adapter-v2 already contains the WS01 language cleanup commits (schema reshape, type expressions, default outcome blocks, stdlib registration). This PR adds only the optional-defaults delta on top.
Clean cherry-pick, no merge conflicts.