Skip to content

adapter-v2: sync optional object defaults from main#169

Merged
brokenbot merged 1 commit into
adapter-v2from
merge-main-into-adapter-v2
May 26, 2026
Merged

adapter-v2: sync optional object defaults from main#169
brokenbot merged 1 commit into
adapter-v2from
merge-main-into-adapter-v2

Conversation

@handcaught
Copy link
Copy Markdown
Member

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 for optional(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.

…#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 brokenbot merged commit 1b2d4cb into adapter-v2 May 26, 2026
6 checks passed
@brokenbot brokenbot deleted the merge-main-into-adapter-v2 branch May 26, 2026 04:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants