Extend test evaluator to support enums, match, arrays, and choices#56
Closed
dragonlightintl wants to merge 2 commits into
Closed
Extend test evaluator to support enums, match, arrays, and choices#56dragonlightintl wants to merge 2 commits into
dragonlightintl wants to merge 2 commits into
Conversation
|
@dragonlightintl is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
16c583d to
24e3128
Compare
…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
24e3128 to
cdf526c
Compare
Author
|
Recreating with clean history — stale merge commit in this PR's history. |
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.
Summary
The
zero testdirect-frontend evaluator currently only handles expressions composed of integer and bool literals,ifstatements, and same-file function calls with primitive-only bodies. This PR extends the evaluator to handle the constructs needed for real-world test coverage:Stage.testingresolves to the case index integer_fallbackGateOutcome.passed) and with payload (HandoffValidation.invalid("reason"))[Stage.testing, Stage.coding]andarr[0]Motivation
Without these constructs, only functions with primitive-only bodies (no
match, no enums, no shapes) can be tested throughzero test. In practice, this means most real pipeline logic — which uses enums and match for exhaustive dispatch — can only be verified viazero check(type-correctness) but not execution-tested.This change enables tests like:
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
STMT_MATCHhandler currently only resolves enum types. Choice match would require additional work to resolve choice discriminants.Test plan
test-blocks.0,test-expected-fail.0,test-expect-runtime-fail.0,test-unexpected-pass.0,test-expect-non-bool.0)-Wall -Wextra -Wpedantic(no new warnings)zero checkbehavior unchanged for all example files