From cf63d2367f0665117aa6d350206ee51d54edc35f Mon Sep 17 00:00:00 2001 From: "Jonathan D.A. Jewell" <6759885+hyperpolymath@users.noreply.github.com> Date: Mon, 18 May 2026 00:51:24 +0100 Subject: [PATCH] fix(stdlib): Iterator::collect uses [] not nonexistent Vec (#135 slice 4-traits) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit traits.affine:124 was the last parse blocker. Root cause is NOT a compiler grammar gap: `while let` already parses. It is broken stdlib code — `Iterator::collect` returned `Vec[Item]` and used `Vec::new()` / `.push()`, but **`Vec` is not defined anywhere in the stdlib** (the whole stdlib builds lists with `[]` + `++`, never `Vec`; `Vec::new()` also exercised an unsupported `Type::lower_fn()` associated-call form). Resolve-at-source: rewrite `collect` in the stdlib's own list idiom (`let mut result = []; while let Some(item) = self.next() { result = result ++ [item]; } return result`) rather than add speculative `Vec` + associated-function grammar to prop up code that never had a `Vec`. Effect: traits.affine clears its last parse wall (PARSE 124 -> TYPECHECK; the remaining `ref 't ~ Int` is a distinct deeper defect in the `impl Eq for Int` blocks). Pure stdlib change — suite unaffected. Advances #135. Refs #128, #135. Co-Authored-By: Claude Opus 4.7 (1M context) --- stdlib/traits.affine | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/stdlib/traits.affine b/stdlib/traits.affine index 90cceca7..2990218e 100644 --- a/stdlib/traits.affine +++ b/stdlib/traits.affine @@ -119,11 +119,13 @@ pub trait Iterator { return n; } - /// Collect into Vec - pub fn collect(mut self) -> Vec[Item] { - let mut result = Vec::new(); + /// Collect into a list. (`Vec` is not a stdlib type; the stdlib + /// builds lists with `[]` + `++`, as in prelude/option/result — + /// #135 slice 4-traits.) + pub fn collect(mut self) -> [Item] { + let mut result = []; while let Some(item) = self.next() { - result.push(item); + result = result ++ [item]; } return result; }