Repository navigation
Description
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()andunreachable()are divergence-oriented builtins with typeNever.
- 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/unreachableare 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).
- more than one argument →
- Existing positive coverage:
test/spec/spec_ss18_6_unreachable_todo_assert_matches.wcoversunreachable()as a zero-arg match fallback andtodo("msg")compiling inside an uncalled function — but no test exercises the two error paths, no test uses a zero-argtodo(), and no test passes a non-literalstrexpression or a wrong-typed argument.
Implementation plan
Test-only issue; no compiler changes. The error-message strings above are the contract the tests pin.
- Add negative fixtures for both diagnostics, for both builtins (the check is shared, but each surface spelling should be locked).
- Add positive fixtures for the accepted forms: zero args; string literal;
str-typed variable/f-string message. - 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 (LLVMunreachable), 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 theexpect-exit/expect-stderrpanic-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 forunreachable("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-argtodo()/unreachable()and one-arg message forms (literal andstrvariable / f-string) inside functions that are never called;unreachable()in value position for a non-Neverexpected type (e.g.let x: i32 = if cond: 1 else: unreachable()withcondtrue) 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 :testpass;with build :test-greenrecorded.
Dependencies
- Bug: todo()/unreachable() lower to LLVM unreachable, not a panic (§29.10, §4.10, §14.11.1) #544 (todo()/unreachable() must lower to a panic with message/file/line, not LLVM
unreachable) — owns the runtime-behavior tests; this issue is sema-diagnostic coverage only. - Unreachable-code detection: goto and Never-call divergence (§20b.5) #543 (reachability/divergence detection) — consumes the
ty_nevertyping these tests touch; coordinate so positive fixtures don't trip new unreachable-code errors (keep diverging calls as the final statement of their block).
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 29.10.1.2.
Activity
ehartford commentedon Jul 3, 2026
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.
test: coverage-sweep batch 2 (#483 #484 #522 #493 #494 #514 #515 #532)