Skip to content

Tests: todo unreachable coverage (§29) #532

Closed

Description

@ehartford

Tests: todo unreachable coverage (§29)

Summary

§29.10 specifies that todo()/unreachable() accept zero arguments or one str-compatible message argument. The argument-arity and argument-type diagnostics are implemented in sema but have zero test coverage; nothing fails today if the checks are deleted. This issue adds the missing positive and negative coverage.

Spec

§29.10 todo and unreachable (docs/with-specification.md:10939-10945):

todo() and unreachable() are divergence-oriented builtins with type Never.

  • They accept zero arguments or one str-compatible message argument.
  • Their type is Never, which is compatible in value position with any expected type.
  • They are treated as diverging control-flow points for typing and reachability analysis.

This issue covers the second bullet (requirement 29.10.1.2). The first bullet's runtime behavior is broken separately (#544: both lower to bare wl_build_unreachable, message discarded), and the third bullet's reachability gap is #543.

Current state

Implemented, untested (requirement verdict 29.10.1.2: "arg diagnostics untested"):

  • todo/unreachable are intrinsic symbols (Sema.is_intrinsic_fn_sym, src/SemaCheck.w:11202-11203).
  • Sema.check_intrinsic_call (src/SemaCheck.w:11267-11277):
    • more than one argument → self.emit_error("todo()/unreachable() expect zero or one message argument", node);
    • one argument whose type is not str-compatible (types_compatible(ty_str, msg_ty) == 0) → self.emit_error("todo()/unreachable() message must be str-compatible", ...);
    • returns self.ty_never (Never-in-value-position typing).
  • Existing positive coverage: test/spec/spec_ss18_6_unreachable_todo_assert_matches.w covers unreachable() as a zero-arg match fallback and todo("msg") compiling inside an uncalled function — but no test exercises the two error paths, no test uses a zero-arg todo(), and no test passes a non-literal str expression or a wrong-typed argument.

Implementation plan

Test-only issue; no compiler changes. The error-message strings above are the contract the tests pin.

  1. Add negative fixtures for both diagnostics, for both builtins (the check is shared, but each surface spelling should be locked).
  2. Add positive fixtures for the accepted forms: zero args; string literal; str-typed variable/f-string message.
  3. Keep runtime assertions out of scope: until Bug: todo()/unreachable() lower to LLVM unreachable, not a panic (§29.10, §4.10, §14.11.1) #544 is fixed, calling todo()/unreachable() at runtime is UB (LLVM unreachable), so all positive tests must keep the calls statically unreached (compile-and-run with the diverging call in a never-invoked function or guarded branch) or be check-only. When Bug: todo()/unreachable() lower to LLVM unreachable, not a panic (§29.10, §4.10, §14.11.1) #544 lands, it adds the expect-exit/expect-stderr panic-message tests; do not duplicate them here.

Test plan

test/compile_errors/:

  • err_todo_two_args.w — todo("a", "b"); //! expect-error: todo()/unreachable() expect zero or one message argument.
  • err_unreachable_two_args.w — same for unreachable("a", "b").
  • err_todo_non_str_message.w — todo(42); //! expect-error: todo()/unreachable() message must be str-compatible.
  • err_unreachable_non_str_message.w — unreachable(true); same expectation.

test/spec/:

  • spec_ss29_10_todo_unreachable_args.w (//! expect-stdout: ok) — compiles and runs: zero-arg todo() / unreachable() and one-arg message forms (literal and str variable / f-string) inside functions that are never called; unreachable() in value position for a non-Never expected type (e.g. let x: i32 = if cond: 1 else: unreachable() with cond true) to lock the Never-compatibility typing alongside the arity rule.

Acceptance criteria

  • Both diagnostics in check_intrinsic_call (src/SemaCheck.w:11267-11276) are pinned by failing tests if removed.
  • Accepted forms (0 args; 1 str-compatible arg, literal or expression) are covered by a passing spec test, including Never-in-value-position usage.
  • No test invokes todo()/unreachable() at runtime (UB until Bug: todo()/unreachable() lower to LLVM unreachable, not a panic (§29.10, §4.10, §14.11.1) #544).
  • 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: 29.10.1.2.

Activity

  1. ehartford commented on Jul 3, 2026

    @ehartford
    ContributorAuthor

    Closing — todo()/unreachable() as Never-typed (value position, optional message) + arity rejection pinned by spec_ss29_todo_unreachable + err_todo_two_args (ec03406). Actual diagnostics differ from the issue's predicted text (per-builtin 'todo() expects zero or one message argument, found N'; wrong-arg-type routes through the generic 'wrong argument type' path) — fixtures pin the real strings. §29.

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