Files
Nim/lib/pure
Rybnikov Alex 393d27b57d fix(stdlib): use first-element flag in $ for collections (#18583) (#25832)
Fixes #18583.

## Problem

Several stdlib collection types compute the separator for `$` using
`result.len > 1`, where `result` starts as the opening bracket (`"["` or
`"{"`). This breaks when a collection element type has a `$` that
returns an empty string: `result.len` stays at 1 after the first item
contributes nothing, so the separator is never inserted for subsequent
items.

```nim
import std/deques

type Test = object
proc `$`(x: Test): string = ""

echo [Test(), Test()].toDeque  # prints [] — expected [, ]
```

## Fix

Replace the length check with an explicit `first` flag in all affected
modules: `deques`, `heapqueue`, `lists`, `critbits`, and `strtabs`.

## Tests

Regression tests added to `tdeques`, `theapqueue`, and `tlists` using a
local type whose `$` returns `""`. All three test files pass with `nim c
-r`.

## Notes

I work with Claude as a co-processor. I'm 56, came to programming late,
and this is genuinely how I learn and contribute. I understand what I'm
submitting, but I didn't write it alone. If your project prefers
human-only contributions, just say so and I'll close without friction.

---------

Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-21 13:40:35 +02:00
..
2026-02-10 13:21:35 +01:00
2015-10-01 12:05:45 -07:00
2024-05-16 23:22:49 +02:00
2025-12-21 19:13:25 +01:00
2026-02-10 13:21:35 +01:00
2021-01-09 00:24:41 +01:00
2026-04-02 07:19:43 +02:00
2026-02-10 13:21:35 +01:00
2024-12-20 15:26:30 +01:00
2026-04-02 07:19:43 +02:00
2022-12-03 21:25:49 +08:00
2026-02-20 16:41:06 +01:00
2024-12-20 15:26:30 +01:00
2026-04-02 07:19:43 +02:00
2026-02-23 13:39:55 +01:00