Repository navigation
Description
Summary
Add tests that pin the §10.1 no-ceremony discard rule for Result and Option. With must not force let _ = expr when a discarded Result or Option has no side effect; an expression statement is already an explicit choice to ignore the value. This issue is coverage for expression-statement discard and should stay separate from #371, which removes the remaining Result partial-match must_use behavior.
Spec
§10.1 Result and Option says errors are values and that discarding Result or Option has no side effect. The compiler "does not require ceremony such as let _ = expr merely to acknowledge that discard"; users should propagate, match, or bind the value when handling matters, otherwise an expression statement is enough (docs/with-specification.md:4105-4124).
Examples this issue should lock down:
fn fallible(ok: bool) -> Result[i32, str]:
if ok: Ok(1) else: Err("no")
fn maybe(ok: bool) -> Option[i32]:
if ok: Some(1) else: None
fn main:
fallible(false) // legal discard
maybe(false) // legal discard
Current state
docs/with-specification.md:4107-4124explicitly forbids requiringlet _ = exprforResult/Optiondiscard.src/SemaCheck.w:4368-4388checks block statements in statement position and emits an unused-value error only for discarded non-scopedTaskvalues (E0801: unused Task value). It does not emit an expression-statement discard error forResultorOption.src/SemaDecl.w:116-122still inserts bothResultandTaskintomust_use_types; Remove Result from the hardcoded @[must_use] set #371 owns removingResultfrom that set. This affects statement-position partialmatch, not bare expression-statement discard.src/SemaCheck.w:6069-6081usesmust_use_typesto force exhaustive statement-position matches forResulttoday; again, that is Remove Result from the hardcoded @[must_use] set #371, not this issue.out/req-campaign/g05.tsvrecords the specific coverage gap for10.1.1.3,10.1.1.4, and10.1.1.5: discard was verified manually, no ceremony is required, expression-statement discard works, but there is no committed test.out/issue-enrich/new/371.mdalready documents and plans the partial-match cleanup. This issue should cross-reference it and avoid duplicating that implementation.
Implementation plan
- Add a behavior test, preferably
test/behavior/behav_result_option_discard.w, that calls functions returningResultandOptionas bare expression statements. Include both success and failure/none paths so the test proves the ignored value itself does not change control flow. - In the same test, include equivalent
let _ = ...examples as allowed style, but keep the primary assertion thatlet _ =is optional, not required. - Add a negative guard for
Taskdiscard intest/compile_errors/unused_task_value.wif current coverage is missing. The point is to show the distinction:Result/Optiondiscard is harmless; droppedTaskhas cancellation semantics and remains an error. - Do not change
src/SemaDecl.wfor this issue unless Remove Result from the hardcoded @[must_use] set #371 is being implemented at the same time. IfResultpartial-match failures block this test, the test was scoped incorrectly; use expression statements, not partial matches. - Update any coverage manifest or spec test index used by the test harness if required by the local test layout.
Test plan
test/behavior/behav_result_option_discard.w:fallible(true)andfallible(false)as expression statements both compile and run.maybe(true)andmaybe(false)as expression statements both compile and run.- Side-effect counters around those calls prove the calls executed even though their wrappers were ignored.
let _ = fallible(false)remains legal style but is not necessary.
test/compile_errors/unused_task_value.wor an existing Task-discard test:- A bare async task expression still produces
E0801: unused Task valuefromsrc/SemaCheck.w:4384-4387.
- A bare async task expression still produces
- Remove Result from the hardcoded @[must_use] set #371 test coverage:
- Statement-position partial
matchonResultbecomes legal there; do not duplicate it here except as a cross-reference.
- Statement-position partial
Acceptance criteria
- Bare expression-statement discard of
Resultis tested and accepted - Bare expression-statement discard of
Optionis tested and accepted -
let _ =remains accepted but is not required by any diagnostic - Task discard remains rejected, preserving the semantic distinction
- Remove Result from the hardcoded @[must_use] set #371 remains the owner for Result partial-match
must_usecleanup -
with build && with build :fixpoint && with build :testpass
Dependencies
Related to #371. This issue can add expression-statement discard coverage before #371, but full §10.1 no-ceremony compliance also needs #371's Result partial-match cleanup.
Traceability
From the requirements campaign (docs/requirements.md, spec v7.1). Affected requirement IDs: 10.1.1.3, 10.1.1.4, 10.1.1.5.
Activity
ehartford commentedon Jul 3, 2026
Closing — bare Result/Option expression-statement discard pinned by behav_result_option_discard (6c59303): side effects run, no ceremony. Task negative already covered by err_unused_task. §10.1.
test: coverage-sweep batch 1 (#495 #496 #521 #518 #529 #492 #499)