Skip to content

Extend test evaluator to support enums, match, arrays, and choices#56

Closed
dragonlightintl wants to merge 2 commits into
vercel-labs:mainfrom
dragonlightintl:dragonlight/compiled-test-backend
Closed

Extend test evaluator to support enums, match, arrays, and choices#56
dragonlightintl wants to merge 2 commits into
vercel-labs:mainfrom
dragonlightintl:dragonlight/compiled-test-backend

Conversation

@dragonlightintl
Copy link
Copy Markdown

@dragonlightintl dragonlightintl commented May 17, 2026

Summary

The zero test direct-frontend evaluator currently only handles expressions composed of integer and bool literals, if statements, and same-file function calls with primitive-only bodies. This PR extends the evaluator to handle the constructs needed for real-world test coverage:

  • Qualified enum access: Stage.testing resolves to the case index integer
  • Match statements: dispatches on enum discriminant, including _ fallback
  • Choice constructors: both nullary (GateOutcome.passed) and with payload (HandoffValidation.invalid("reason"))
  • Array literals and indexing: [Stage.testing, Stage.coding] and arr[0]
  • Variable assignment and while loops
  • Null literals and type casts

Motivation

Without these constructs, only functions with primitive-only bodies (no match, no enums, no shapes) can be tested through zero test. In practice, this means most real pipeline logic — which uses enums and match for exhaustive dispatch — can only be verified via zero check (type-correctness) but not execution-tested.

This change enables tests like:

test "retry_budget_for returns correct budgets" {
    let config = default_config()
    expect(retry_budget_for(config, Stage.testing) == 2)
}

Approach

Extends the existing AST interpreter rather than introducing a compiled-test backend. The evaluator already handled if, let, return, expect, binary operators, shape literals, shape field access, and function calls. This PR adds handlers for the remaining common AST node types.

All changes are in native/zero-c/src/main.c (+208 lines).

What's NOT included

  • Choice match dispatch (matching on choice type discriminants) — the STMT_MATCH handler currently only resolves enum types. Choice match would require additional work to resolve choice discriminants.
  • Cross-module function resolution in test scope — functions from imported modules still fail. This is a separate issue from expression evaluation.

Test plan

  • All existing conformance test fixtures produce identical results (test-blocks.0, test-expected-fail.0, test-expect-runtime-fail.0, test-unexpected-pass.0, test-expect-non-bool.0)
  • Builds cleanly with -Wall -Wextra -Wpedantic (no new warnings)
  • New enum access, match dispatch, shape construction, array literal, and choice constructor expressions evaluate correctly in test blocks
  • Existing zero check behavior unchanged for all example files

@vercel
Copy link
Copy Markdown

vercel Bot commented May 17, 2026

@dragonlightintl is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

@dragonlightintl dragonlightintl force-pushed the dragonlight/compiled-test-backend branch from 16c583d to 24e3128 Compare May 17, 2026 21:20
…pressions

The direct-frontend test backend was an AST-level interpreter that only
supported primitives and if statements. Any test whose call chain touched
match, qualified enum access (Stage.testing), shape construction with
enum fields, array literals, or index expressions would fail with
"unknown identifier", "does not support this expression yet", or
"does not support this statement yet".

This extends the interpreter to handle the missing constructs:
- Qualified enum access (Stage.testing) resolves to the case index
- Match statements evaluate the discriminant and dispatch to the
  matching arm, including fallback (_) arms
- Choice constructors (ChoiceName.variant(payload)) in both nullary
  member-access form and call form
- Array literal expressions (EXPR_ARRAY_LITERAL)
- Array index expressions (EXPR_INDEX)
- Variable assignment statements (STMT_ASSIGN)
- While loop statements (STMT_WHILE)
- Null literals (EXPR_NULL)
- Cast expressions (EXPR_CAST) pass through to the inner value
@dragonlightintl dragonlightintl force-pushed the dragonlight/compiled-test-backend branch from 24e3128 to cdf526c Compare May 17, 2026 21:41
@dragonlightintl
Copy link
Copy Markdown
Author

Recreating with clean history — stale merge commit in this PR's history.

@dragonlightintl dragonlightintl deleted the dragonlight/compiled-test-backend branch May 17, 2026 22:30
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.

1 participant