Skip to content

Tests: labels goto edge cases coverage (§13) #506

Closed

Description

@ehartford

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

  1. Add a warning test for an unused label and assert the unused-label warning code/message.
  2. Add behavior tests where a goto exits a scope containing a with guard or defer, proving cleanup runs exactly once.
  3. Add a behavior test where goto exits a scope containing errdefer, proving errdefer does not run on non-error goto.
  4. Add do-while tests for continue plus defer/errdefer, proving continue jumps to the condition and normal cleanup semantics still hold.
  5. 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 continue and 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

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    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.

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