Skip to content

Tests: with control flow coverage (§23, §7) #536

Closed

Description

@ehartford

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 with forms are transparent for control flow. The following observable behaviors are required:

  • return inside a with block returns from the enclosing function.
  • break inside a with block breaks the enclosing loop.
  • continue inside a with block continues the enclosing loop.
  • Labeled break 'label and continue 'label inside a with block may target visible labels in the enclosing function; with blocks do not hide labels.
  • goto 'label inside a with block may target a visible label in the enclosing function, subject to the normal goto restrictions (§13.5b).
  • ? inside a with block 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:

  • with lowers via inline desugaring (plain forms per §23.1) and guarded forms with guard cleanup drop kinds DK_WITH_GUARD/DK_WITH_GUARD_MUT (src/Mir.w:317-318), released by emit_with_guard_cleanup (src/MirLower.w:213, the guard exit/release call path invoked from emit_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 a with guard 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 with tests (test/spec/spec_ss07_*.w, test/mut_with_*.w, test/behavior/type_with_clause.w) cover dispatch, guards, builders — none combine with with break/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.

  1. Use both with flavors per behavior where it matters: a plain binding form (with e as x:) and a guarded form (a user guard type with enter/exit or Drop-observable release that prints release), so the test observes both the transfer and the exactly-once guard release ordering relative to the transfer.
  2. Mirror the three §7.7 examples directly so the spec's own code is what the suite runs.
  3. For ?: a with block inside a Result-returning function where the guarded body calls a failing fallible fn; assert the error reaches the caller and the guard was released during propagation.
  4. For goto: target a label after the with block (forward goto per §13.5b restrictions); assert guard release happened before the labeled continuation runs (this is also the 13.5.3.x with-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/while loop, guarded with in body, conditional break; expect loop exits early, guard released once per iteration including the breaking one (req 23.3.1.4).
  • spec_ss23_3_with_continue.w — continue inside with; expect skipped iterations still release the guard (req 23.3.1.5; §7.7 process_all shape).
  • spec_ss23_3_with_labeled_break.w — 'outer for ... : with g: break 'outer (§7.7 process_until_done example) plus a labeled continue 'outer variant; both labels visible through the with (req 23.3.1.6).
  • spec_ss23_3_with_goto.w — goto 'done from inside a with block to a label after it; expect release printed before the 'done continuation (reqs 23.3.1.7, 7.7.1.5).
  • spec_ss23_3_with_try.w — ? inside with propagates an Err to the enclosing function; caller observes the error; guard released (reqs 23.3.1.8, 7.7.1.6; §7.7 validate(item)? shape).
  • spec_ss07_7_with_control_flow.w — the §7.7 find_value match-arm return 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 — a goto from inside a with block that violates a §13.5b restriction (e.g. backward/into-scope jump) is rejected with the same diagnostic as outside a with (locks "subject to the normal goto restrictions").

Acceptance criteria

  • Each of break, continue, break 'label, continue 'label, goto 'label, and ? inside a with block 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.6 flip from "untested" to test-backed.
  • with build && with build :fixpoint && with build :test pass; with build :test-green recorded.

Dependencies

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

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    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 inside with). 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 explicit return as 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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions