Skip to content

precondition_lazy.w: require/check messages are evaluated eagerly; the test claims lazy and the substring runner hid it #1864

Closed

Description

@ehartford

precondition_lazy.w claims require/check evaluate their message lazily; they do not, and the substring runner never noticed

Found by #1855's exact expect-stdout rule. test/behavior/precondition_lazy.w:

//! expect-stdout: ok

// Test: lazy message evaluation.
// The message expression must NOT be evaluated when the condition is true.
fn side_effect() -> str:
    print("SHOULD NOT PRINT")
    "message"
fn main:
    require(true, side_effect())
    check(true, side_effect())
    print("ok")

Actual stdout:

SHOULD NOT PRINT
SHOULD NOT PRINT
ok

The old runner passed it because ok is a substring of the output. lib/std/builtins.w declares require(cond: bool, msg: &str, loc: &str = src()) and check the same, so the message is an ordinary argument, evaluated before the call. The spec (§10, §9) says nothing about lazy messages for require/check (?? and unwrap_or_else are the documented lazy forms).

Maintainer's call: either the message becomes lazy (a fn() -> str / closure form, or a language rule) and the spec says so, or the fixture's claim goes. Until then the fixture carries //! known-issue: for this issue and stays red under the exact rule.

Activity

  1. added
    bug
    on Sep 28, 2026
  2. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Decision brief (coordinator, 2026-10-03; from the wave-build agent, verified against the spec).

    1. Others. Swift precondition(_:_:) takes the message as @autoclosure — evaluated only on failure, no caller ceremony. Rust assert!/debug_assert! evaluate the format arguments only when the assertion fails. Zig's assert takes no message.
    2. Spec. No chapter says require/check messages are lazy; the only lazy forms the spec names are ?? and with_context. test/behavior/precondition_lazy.w claims laziness that the implementation doesn't have (the substring runner hid it; #1855 fixed the runner half).
    3. Mission fit. Lazy: an expensive message (formatting, a lookup) never runs on a passing check, and the user writes nothing extra — a message is obviously only needed on failure. Eager would make users hoist checks into an if to avoid the cost: ceremony.
    4. Prediction. Eric rules lazy, Swift-style, ~80%.
    Draft words (preconditions chapter): "The message operand of require and check is evaluated only when the condition is false."

  3. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Eric's direction (2026-10-03): lazy, with the mechanism stated. Revised draft words for the preconditions chapter (need Eric's blessing of the words):

    assert, require, check and their std.testing forms are compiler-known forms, not functions. Each evaluates its message operand only when its condition is false. The message operand follows the rules of the right operand of ??: its effects do not run when the condition holds, and a move inside it is a conditional move.

    No general lazy-parameter feature is introduced. The silent tool half (the substring runner) was #1855, fixed 2026-09-29; this issue is the false claim it hid.

  4. added 3 commits that reference this issue on Oct 3, 2026
  5. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Fixed on main in 74e3001 (stack #2032; seed-driven battery GREEN on 2b9ad28, tree identical to main).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions