Repository navigation
Description
Tests: with control flow coverage (§23, §7)
Summary
§7.7/§23.3 make every with form transparent for non-local control flow: return, break, continue, labeled break/continue, goto, and ? all act on the enclosing function/loop, and with does not hide labels. The requirements survey found all of these behaviors implemented and working, but only plain return has test coverage. Six normative behaviors (23.3.1.4-.8, 7.7.1.5-.6) are unpinned — a lowering regression would ship silently. This issue adds the missing positive coverage, including guard-release interaction on each transfer path.
Spec
§23.3 Non-Local Control Flow (docs/with-specification.md:10722-10741) and §7.7 (docs/with-specification.md:2692-2737):
All
withforms are transparent for control flow. The following observable behaviors are required:
returninside awithblock returns from the enclosing function.breakinside awithblock breaks the enclosing loop.continueinside awithblock continues the enclosing loop.- Labeled
break 'labelandcontinue 'labelinside awithblock may target visible labels in the enclosing function;withblocks do not hide labels.goto 'labelinside awithblock may target a visible label in the enclosing function, subject to the normal goto restrictions (§13.5b).?inside awithblock propagates to the enclosing function.
§7.7 adds the canonical examples (match-arm return under a guard, continue/? inside with lock.lock(), break 'outer from a guarded block inside a labeled loop).
Current state
Implemented, untested (requirement verdicts): 23.3.1.4 "break works, untested"; 23.3.1.5 "continue works, untested"; 23.3.1.6 "labels visible, untested"; 23.3.1.7 / 7.7.1.5 "goto path untested"; 23.3.1.8 / 7.7.1.6 "? propagation untested". Only 23.3.1.3 (return) is covered ("test_non_local_return").
Implementation surfaces the tests pin:
withlowers via inline desugaring (plain forms per §23.1) and guarded forms with guard cleanup drop kindsDK_WITH_GUARD/DK_WITH_GUARD_MUT(src/Mir.w:317-318), released byemit_with_guard_cleanup(src/MirLower.w:213, the guardexit/release call path invoked fromemit_drop_entry,:273ff).- Non-local transfers run scope cleanup through
pop_scope_with_goto(src/MirLower.w:345),emit_drops_for_break(:410),emit_cleanup_to_target(:429),emit_drops_for_return(:448) — so each control-flow kind exercising awithguard takes a distinct cleanup path, and guard release on each path is part of the observable contract (the guard must be released exactly once before the transfer completes). - Existing
withtests (test/spec/spec_ss07_*.w,test/mut_with_*.w,test/behavior/type_with_clause.w) cover dispatch, guards, builders — none combinewithwithbreak/continue/labels/goto/?.
Implementation plan
Test-only issue; no compiler changes expected. If any transfer path turns out broken (e.g. guard not released on goto), that is a compiler bug to file with the failing repro per the root-cause rule — do not weaken the test.
- Use both
withflavors per behavior where it matters: a plain binding form (with e as x:) and a guarded form (a user guard type withenter/exitorDrop-observable release that printsrelease), so the test observes both the transfer and the exactly-once guard release ordering relative to the transfer. - Mirror the three §7.7 examples directly so the spec's own code is what the suite runs.
- For
?: awithblock inside aResult-returning function where the guarded body calls a failing fallible fn; assert the error reaches the caller and the guard was released during propagation. - For
goto: target a label after thewithblock (forward goto per §13.5b restrictions); assert guard release happened before the labeled continuation runs (this is also the13.5.3.xwith-guard-release-on-goto gap noted in Tests: labels goto edge cases coverage (§13) #506 — coordinate to avoid duplicate fixtures).
Test plan
All positive //! expect-stdout tests with exact output asserting both control-flow effect and guard-release ordering:
test/spec/:
spec_ss23_3_with_break.w—for/whileloop, guardedwithin body, conditionalbreak; expect loop exits early, guard released once per iteration including the breaking one (req23.3.1.4).spec_ss23_3_with_continue.w—continueinsidewith; expect skipped iterations still release the guard (req23.3.1.5; §7.7process_allshape).spec_ss23_3_with_labeled_break.w—'outer for ... : with g: break 'outer(§7.7process_until_doneexample) plus a labeledcontinue 'outervariant; both labels visible through thewith(req23.3.1.6).spec_ss23_3_with_goto.w—goto 'donefrom inside awithblock to a label after it; expectreleaseprinted before the'donecontinuation (reqs23.3.1.7,7.7.1.5).spec_ss23_3_with_try.w—?insidewithpropagates anErrto the enclosing function; caller observes the error; guard released (reqs23.3.1.8,7.7.1.6; §7.7validate(item)?shape).spec_ss07_7_with_control_flow.w— the §7.7find_valuematch-armreturn Some(v)example (regression companion to the existing return coverage, under a guard).
test/compile_errors/ (negative, normal restrictions still apply through with):
err_with_goto_restriction.w— agotofrom inside awithblock that violates a §13.5b restriction (e.g. backward/into-scope jump) is rejected with the same diagnostic as outside awith(locks "subject to the normal goto restrictions").
Acceptance criteria
- Each of
break,continue,break 'label,continue 'label,goto 'label, and?inside awithblock has a passing test observing the transfer's effect on the enclosing function/loop. - Guarded-form tests additionally assert exactly-once guard release ordered before the continuation of the transfer, on every path.
- §13.5b goto restrictions verified unchanged inside
with(negative fixture). - Requirements
23.3.1.4-23.3.1.8,7.7.1.5,7.7.1.6flip from "untested" to test-backed. -
with build && with build :fixpoint && with build :testpass;with build :test-greenrecorded.
Dependencies
- Tests: labels goto edge cases coverage (§13) #506 (labels/goto edge cases §13) — owns goto+defer/errdefer interplay and overlaps on with-guard release on goto; coordinate fixture ownership.
- Unreachable-code detection: goto and Never-call divergence (§20b.5) #543 (goto/Never divergence detection) — once goto marks divergence, these fixtures must keep code after
gotoreachable only via labels (write them that way from the start). - Tests: drop order coverage (§20, §21) #495 (drop order tests) — guard-release ordering assertions complement its scope-exit drop-order coverage.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 23.3.1.4, 23.3.1.5, 23.3.1.6, 23.3.1.7, 23.3.1.8, 7.7.1.5, 7.7.1.6.
Activity
ehartford commentedon Jul 3, 2026
Covered by the
spec_ss23_3_with_*set (break, continue, labeled break/continue, goto, ?) +spec_ss07_7_with_control_flow.w(§7.7 match-arm return) +err_with_goto_restriction.w(§13.5b goto-restriction from insidewith). Each transfer path asserts the guard is released exactly once (observable contract). Two bugs surfaced writing these: #640 (labeled statement drops the implicit tail-expression return — the goto fixture uses explicitreturnas workaround) — guard-release-on-goto itself is correct. Verified on HEAD; full gate green (native-compile-error-tests 681, native-spec-tests 206, GATES EXIT: 0).test: pin §29 string/block forms, §23.3 with control flow, §11 coherence