Skip to content

Comptime build.w evaluator: ?? on an Option is not evaluable (match is) #1041

Closed

Description

@ehartford

Restated 2026-10-25. match on an Option now evaluates in the comptime build evaluator. What is left: ?? on an Option does not, so fs.read_text_opt(p) ?? "" cannot run in build.w.


Original report

Found while landing #953: ToolFs.read_text_opt -> Option[str] is the optional-file probe, and the intended driver spelling is fs.read_text_opt(p) ?? "". Under the pub fn build(ctx: BuildCtx) comptime evaluator (src/ComptimeEval.w) that spelling cannot run — neither ?? nor match on an Option is comptime-evaluable, for any Option, not just the new method. .is_none() / .is_some() / .unwrap() work (eval_option_method_call).

Pre-existing: reproduces with the seed v0.15.1.7-gafab48503 (a plain Vec.pop() Option shows it).

Spec reference: §10.2 (??), §9.7 (pattern matching on Option); §18.5c build.w is ordinary With.

Repro 1 — ?? (with build in a project whose build.w is):

use std.build

pub fn build(ctx: BuildCtx) -> Build:
    var v: Vec[i32] = Vec.new()
    let x = v.pop() ?? 7
    assert(x == 7)
    ctx.new_build().executable("app", "src/main.w")

Actual: error: operator requires integer comptime values (the ?? node falls into the integer binary-operator path).

Repro 2 — match on an Option:

use std.build

pub fn build(ctx: BuildCtx) -> Build:
    var v: Vec[i32] = Vec.new()
    v.push(1)
    match v.pop():
        Some(x) => assert(x == 1)
        None => assert(false)
    ctx.new_build().executable("app", "src/main.w")

Actual: error: no comptime match arm matched (subject kind=13 data0=219) — the Some(x) / None arms never match the evaluator's enum value (variant symbol syms.some / syms.none).

Expected: both evaluate as they do natively (the #921 native action runner handles the same code in an ActionCtx action without trouble).

Consequence for #953: build/ probe sites are written as if fs.exists(p): fs.read_text(p) else: "" (dual-valid with the pre-#953 seed); moving them to fs.read_text_opt(p) ?? "" after the reseed needs this fixed first. The cli-selfhost-build-w-tests read-missing fixture uses .is_none() / .unwrap() for the same reason.

Activity

  1. changed the title [-]Comptime build.w evaluator: `??` and `match` on an Option are not evaluable (blocks `read_text_opt(p) ?? ""` in build/)[/-] [+]Comptime build.w evaluator: ?? on an Option is not evaluable (match is)[/+] on Oct 25, 2026
  2. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced for ??.

    $ cat build.w   # in a sandbox project
    fn pick(o: Option[str]) -> str: o ?? "default"
    comptime with BuildCtx as ctx:
    pub fn build -> Build:
        let a = pick(None)
        …
    $ with build :show
    error: …/build.w:3:33: operator requires integer comptime values; reached through __with_build_eval_entry -> build -> pick
    # the same file with `match o: Some(v) => v; None => "none"` instead: green, prints "skip x"
    

    pre-release: an ordinary build.w spelling fails with a misleading message; the evaluator already handles the match form.

  3. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 3f96513 (PR #2673, stack #2678; battery green on the stack top 0008bf2). The commit message names the root-cause line and the regression test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions