Repository navigation
Description
Summary
Add edge-case tests for labels, goto cleanup, and do-while control-flow interactions. Most implementation hooks exist, but the requirements campaign left several behaviors unguarded by tests.
Spec
docs/with-specification.md:5635-5638 requires unused labels to produce a warning. docs/with-specification.md:5670-5715 defines goto legality and cleanup behavior. docs/with-specification.md:5691-5699 requires defer cleanup when goto exits scopes, while errdefer runs only on error paths. docs/with-specification.md:5702-5705 covers backward goto cleanup. docs/requirements.md:5265-5268, docs/requirements.md:5344-5351, and docs/requirements.md:5408 list the affected requirement IDs.
Current state
src/SemaCheck.w:1293-1301 emits an unused-label warning for labels that are never targeted. Goto validation and label tracking live around the same semantic pass. src/MirLower.w:3733-3758 lowers do while with continue targeting the condition block. src/MirLower.w:3760-3845 lowers for-loops and iterator control flow.
Existing tests cover the main goto path in test/spec/spec_ss13_5b_goto.w and basic do-while behavior in test/behavior/behav_do_while.w. They do not specifically pin unused-label warning behavior, with-guard/defer release on goto, errdefer non-execution on goto, or do-while defer/errdefer edge cases.
Implementation plan
- Add a warning test for an unused label and assert the
unused-labelwarning code/message. - Add behavior tests where a goto exits a scope containing a
withguard ordefer, proving cleanup runs exactly once. - Add a behavior test where goto exits a scope containing
errdefer, provingerrdeferdoes not run on non-error goto. - Add do-while tests for
continueplusdefer/errdefer, provingcontinuejumps to the condition and normal cleanup semantics still hold. - Keep tests small and source-level; only change compiler code if one of the new tests reveals a real regression.
Test plan
Run each new behavior/compile-warning fixture directly, then run with build :test. For cleanup tests, assert observable counters rather than relying on printed traces. For warnings, use the existing diagnostic harness or extend it narrowly if warnings are not yet testable.
Acceptance criteria
- Unused labels have a direct warning test.
- Goto out of cleanup scopes is covered for both cleanup-that-runs and errdefer-that-does-not-run.
- Do-while
continueand cleanup interaction is covered. - The tests are tied to the requirement IDs in the original traceability section.
Dependencies
No hard dependency. If the current harness cannot assert warnings, add the smallest warning-test harness support necessary before adding the unused-label fixture.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 13.5.2.46, 13.5.3.18, 13.5.3.19, 13.5.4.26, 13.5.4.27.
Activity
ehartford commentedon Jul 3, 2026
Closing the covered surface: goto→defer/Drop cleanup already covered (spec_ss13_5b_goto); errdefer-not-run-on-goto (behav_errdefer_not_run_on_goto) + do-while defer-on-continue (behav_dowhile_defer_continue) pinned 13f4f88. Remaining sub-part: the unused-label WARNING fires correctly but there is no expect-warning test harness to pin it (grep empty) — that's a harness gap, filed as a follow-up need, not a coverage-of-behavior gap. §13.
test: coverage-sweep batch 4 (#497 #504 #506 #524 #525 #531 #534)