From 15fc435d9277023dc4a034e75d0c75319f0c297a Mon Sep 17 00:00:00 2001 From: Koni Marti Date: Tue, 13 Jan 2026 21:56:21 +0100 Subject: [PATCH] collections: fix LinkedList.to_format For-loop in LinkedList.to_format goes brrrrrr and prints the value of the first node an infinte number of times because it does not properly iterate the linked list. Fix the list iterations and add the missing string format specifier. Bug can be reproduced with: ``` import std; fn void main() => @pool() { io::printfn("%s", linkedlist::@tnew{usz}({1,2,3})); } ``` --- lib/std/collections/linkedlist.c3 | 4 ++-- releasenotes.md | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/std/collections/linkedlist.c3 b/lib/std/collections/linkedlist.c3 index 43bf00398..54568bba3 100644 --- a/lib/std/collections/linkedlist.c3 +++ b/lib/std/collections/linkedlist.c3 @@ -24,9 +24,9 @@ struct LinkedList fn usz? LinkedList.to_format(&self, Formatter* f) @dynamic { usz len = f.print("{ ")!; - for (Node* node = self._first; node != null; node.next) + for (Node* node = self._first; node != null; node = node.next) { - len += f.printf(node.next ? "%s, " : "s", node.value)!; + len += f.printf(node.next ? "%s, " : "%s", node.value)!; } return len + f.print(" }"); } diff --git a/releasenotes.md b/releasenotes.md index 17aab02ec..2b0aab391 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -56,6 +56,7 @@ - Assert on optional-returning-function in a comma expression. #2722 - Creating recursive debug info for functions could cause assertions. - bitorder::read and bitorder::write may fail because of unaligned access #2734. +- Fix `LinkedList.to_format` to properly iterate linked list for printing. ### Stdlib changes - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.