Skip to content

Add a ConcurrentStack DeepClone overload that keeps pop order [patch] - #112

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/concurrentstack-deepclone-102
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/concurrentstack-deepclone-102

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

ConcurrentStack<T> had no dedicated overload, so stack.DeepClone() bound to the IEnumerable<T> overload and returned the elements top-first. Rebuilding a stack from that sequence silently reversed the pop order.

This adds public static ConcurrentStack<T> DeepClone<T>(this ConcurrentStack<T> source):

IDE0305 is suppressed on this method, with a justification. The analyzer wants a spread, but a spread would enumerate the stack instead of taking the atomic snapshot (see #100).

The README's container table now lists the overload.

Validation:

  • New ConcurrentStackCloneTests check the returned type, the pop order (3, 2, 1), element independence, and the empty case.
  • With the overload removed, the test project fails to compile (the typed assignment). Making that one line untyped instead leaves the pop-order and element tests failing at runtime.
  • With the overload, all 69 tests pass, and the library builds in Release for every target framework with 0 warnings.

Fixes #102


Generated by Claude Code

ConcurrentStack had no dedicated overload, so DeepClone bound to the
IEnumerable overload and returned a top-first sequence; rebuilding a
stack from it reversed the pop order. Clone from one ToArray snapshot,
reversed, the same way the Stack overload does.

Fixes #102

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW1vQbunMqKm6mgn4pF
@sonarqubecloud

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConcurrentStack<T> has no DeepClone overload, so the clone comes back as IEnumerable<T> and rebuilding a stack from it reverses pop order

2 participants