Skip to content

A pipeline's result cannot take ?? without parentheses; a comprehension is not comptime-evaluable #2142

Closed

Description

@ehartford

Found shortening README examples (2026-10-04, installed v0.15.3.0, main 353992b).

1. ?? after a pipeline needs parentheses.

fn largest(xs: &Vec[f64]): xs.iter() |> max() ?? 0.0

error: undefined variable at the ??. (xs.iter() |> max()) ?? 0.0 compiles. Expected: ?? applies to the pipeline's result, as it does to a method chain's.

2. A list comprehension in a comptime fn.

comptime fn squares(n: i32): [i * i for i in 0..n]
const SQUARES: Vec[i32] = comptime squares(8)

error: expression kind 64 is not comptime-evaluable yet. The loop form (var table = Vec[i32].new(), for i in 0..n: table.push(i * i)) evaluates; the README still uses it for that reason.

3. A bare None inside a tuple compared with a typed tuple.

(Some("a".to_lower()), 1) == (None, 1)

error: comparison operands must have the same tuple type: (Option[str], i32) and (Option, i32). The left operand's type decides the right's.

Workarounds in use: the parentheses in README's largest; the loop in README's squares; a typed binding in test/behavior/behav_2137_structural_equality.w.

Activity

  1. ehartford commented on Oct 5, 2026

    @ehartford
    ContributorAuthor

    More of the same family, found testing #2145 (same on main a45324c):

    1. for (i, x) in names.iter() |> enumerate(): … → "cannot iterate over EnumerateIter[VecIter[str], str]: a for iterable implements Iter[T] …". A pipeline's adapter is not a for iterable.
    2. names.iter() |> position(it == "a") → "comparison operands must have compatible types" at it == "a" (any(it == "a") is fine).
    3. let kept = names.iter() |> filter(…) |> collect[Vec]() is a Vec[&str]; kept[0] == "a" → "comparison operands must have compatible types" (a view of a view of a str against a str).
    4. xs.iter_ref() |> sum() over Vec[i32] → invalid LLVM (add ptr): sum over views of a Copy element has no materialization. This is what stops Vec.iter() yielding views for Copy elements too (D22 contextual Copy in pipelines).
  2. ehartford commented on Oct 5, 2026

    @ehartford
    ContributorAuthor

    Item 1 is the spec's precedence, not a parser bug: §9.9's table puts ?? at level 10 with +, and |> at level 5, so xs.iter() |> max() ?? 0.0 is xs.iter() |> (max() ?? 0.0), and max alone is an undefined name. The compiler conforms.

    It needs a ruling to change. Recommendation: move ?? below |> (its own level between 4 and 5), so a default applies to the pipeline's result. That is the reading a reader assumes, and stage() ?? d as a pipeline stage has no use I can construct. C# puts ?? near the bottom of its table; Swift's nil-coalescing sits above comparison and below arithmetic casts; neither has a pipeline operator to rank against. Cost: a + b ?? c would become (a + b) ?? c instead of a + (b ?? c); a sweep of the tree for ?? beside an arithmetic or bitwise operator would show whether anything relies on today's grouping.

  3. ehartford commented on Oct 5, 2026

    @ehartford
    ContributorAuthor

    Item 2 (a comprehension at comptime) landed in #2151 (main 6b0c99d); README's squares is one line. Item 1 waits for a precedence ruling (see above). Items 3 to 7 are open.

  4. ehartford commented on Oct 5, 2026

    @ehartford
    ContributorAuthor

    Items 3, 5, 6 and 7 landed on main 0ade380 (#2172); item 4 landed with #2150; item 2 with #2151. Only item 1 (the precedence of ?? against |>) is open, and it waits for a ruling.

  5. ehartford commented on Oct 5, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by stack #2196 (merged as efb765c), battery green on a21e326; the regression test for it landed with the fix.

  6. ehartford commented on Oct 5, 2026

    @ehartford
    ContributorAuthor

    All three parts verified on the merged tree: (1) xs.iter() |> max() ?? 0.0 parses (D95 precedence); (2) comptime fn squares(n: i32): [i * i for i in 0..n] evaluates (SQUARES.len() == 8); (3) (Some("a".to_lower()), 1) == (None, 1) type-checks and is false.

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