Expand description
Behavioral evaluation of signature-level examples { ... } blocks (#369 slice 2).
Slice 1 (PR #370) shipped the AST + parser + type-checking of example args
and expected values against the function’s signature. This pass takes the
next step: it actually runs each example through the bytecode VM and
compares the result to the declared expected value. A mismatch becomes
a TypeError::ExampleMismatch with rule_tag = "example-mismatch",
surfaced through the same structured-JSON error envelope as every other
lex check diagnostic.
§Implementation strategy
For each pure function with non-empty examples, synthesize a small set of zero-argument helper functions and append them as new stages alongside the original program:
__ex_<fn>_<K>_arg_<I>returning the Ith argument of case K.__ex_<fn>_<K>_expectedreturning the declared expected value of case K.
Compile the augmented program to bytecode (the user’s program plus the helpers all see the same global scope), and for each case:
- Call each
__ex_<fn>_<K>_arg_<I>helper through the VM to get a runtimeValuefor the argument. - Call the original function with those values to get the actual
Value. - Call
__ex_<fn>_<K>_expectedto get the declaredValue. - Compare the two via
Value’sPartialEq. On mismatch, emitExampleMismatchwith pretty-printedexpectedandgot.
§v1 restrictions
- Generic functions (with
type_params) are skipped — the helper synthesis would need to monomorphize. Examples on generic functions still get the slice-1 type-level checks; they just don’t get behavioral checks. Worth a follow-up issue if examples on generics become a real need. - Pure-only (already enforced by
ExamplesOnEffectfulFnin slice 1).
Functions§
- evaluate_
examples - Run the behavioral-evaluation pass over
stagesand return anyExampleMismatcherrors discovered. Returns the empty vec when every example case passes (or when there are no eligible cases).