Repository navigation
Description
Tests: default op coverage (§10)
Summary
The ?? default operator is implemented, but four of its spec'd behaviors are only "verified manually" (campaign survey): RHS laziness, the break/continue early-exit forms, the labeled forms, and the match desugaring. Only the basic value-default and the ?? return form are in the suite. This adds the missing positive coverage so regressions in lower_double_question are caught.
Spec
§10.4 Default Operator (??):
- "
expr ?? defaultdesugars toexpr.unwrap_or(default). The right-hand side is lazily evaluated (only computed if left isNone)." (10.4.1.3, 10.4.1.7 — the normative desugar to thematchform is given explicitly) - "Early exit form:
??can be followed byreturn,break, orcontinuefor early exit onNone." (10.4.1.4) - "The
breakandcontinueforms may include labels (§13.5a):let token = lexer.peek() ?? break 'scan" (10.4.1.5)
Current state
- Implementation:
MirBuilder.lower_double_question(src/MirLower.w:6568ff), dispatched from the binary-op lowering atsrc/MirLower.w:7782. Campaign verdicts 10.4.1.1/.2 ok; .3/.4/.5/.7 areok|gap— behavior verified manually, untested. - Existing test:
test/spec/spec_ss10_4_default_operator.w(20 lines) covers: basic default, chaineda ?? b ?? c ?? 0, and?? return Err(...)only. No laziness test, nobreak/continue, no labels, no desugar-equivalence check.
Implementation plan
Test-only issue; no compiler changes expected. If any listed form fails, that is a new compiler bug: file it with the repro and do not work around it in the test (AGENTS.md).
- Extend
test/spec/spec_ss10_4_default_operator.w(or addtest/spec/spec_ss10_4_default_operator_forms.wif it grows past readability) with the cases in the test plan. - For laziness, use a helper whose evaluation is detectable without globals:
fn boom() -> i32: assert(false, "?? rhs evaluated eagerly")—Some(5) ?? boom()must not trip it; and a counter variant (varlocal + closure or Vec push) proving the RHS is evaluated exactly once onNone. - Mirror the §10.4 desugaring example as an equivalence test: same input through
??and through the explicitmatchform; assert equal results.
Test plan
All positive cases in test/spec/spec_ss10_4_default_operator*.w (assert-based, //! expect-stdout: ok convention of sibling tests):
- Laziness (10.4.1.3):
Some(5) ?? boom()returns 5 without evaluatingboom;(None: Option[i32]) ?? lazy()evaluateslazyexactly once. - Early-exit return (10.4.1.4): existing
?? return Err(...)kept; add a plain-value?? return 0form in a non-Result fn. - Early-exit break (10.4.1.4):
while true:loop popping from a Vec-backed stack:let item = stack.pop() ?? break; assert items seen and loop exited. - Early-exit continue (10.4.1.4): iterate
Vec[Option[i32]]withlet v = item ?? continue; assert only Some payloads accumulated. - Labeled forms (10.4.1.5): nested loops with
'outer:label:?? break 'outerexits both levels;?? continue 'outeradvances the outer loop — assert iteration counts. - Desugar equivalence (10.4.1.7):
find_user(id) ?? return Err(.NotFound)behaves identically to the spec's expandedmatch ... Some(v) => v / None => return ...form for both Some and None inputs. - Chaining regression: keep
a ?? b ?? c ?? 0(10.4.1.1). - Negative (compile error):
test/compile_errors/default_op_type_mismatch.w—Some(1) ?? "str"(RHS type incompatible with payload) →//! expect-error:with the actual diagnostic text observed (pin after running once; do not guess the message).
Acceptance criteria
- Requirements 10.4.1.3, 10.4.1.4, 10.4.1.5, 10.4.1.7 each have at least one passing automated test
- Any behavior found broken is filed as its own compiler bug with spec reference, not patched around in tests
- with build && with build :fixpoint && with build :test pass (with build :test-green updated)
Dependencies
None blocking. Related: #515/#521 (sibling §10 coverage issues); ?? on chains interacts with ?. (covered in #515's chain+default case, already present in spec_ss10_3_optional_chaining.w).
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 10.4.1.3, 10.4.1.4, 10.4.1.5, 10.4.1.7.
Activity
ehartford commentedon Jul 3, 2026
Closing — ?? laziness (RHS unevaluated when LHS is Some), control-flow RHS (break), and payload-type-mismatch rejection pinned (spec_ss10_4_default_op_control_flow + err_default_op_type_mismatch, ec03406). §10.4. (Inline Some(x) as the ?? operand hits codegen bug #634, worked around via a bound Option local.)
test: coverage-sweep batch 2 (#483 #484 #522 #493 #494 #514 #515 #532)