You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ConcurrentStack<T> has no DeepClone overload, so the clone comes back as IEnumerable<T> and rebuilding a stack from it reverses pop order #102
That overload returns the elements top-first as an IEnumerable<T>. The obvious way to get a stack back is to pass that sequence to the constructor, which pushes the elements in that order and silently reverses the stack.
Repro (net10.0)
varcs=newConcurrentStack<int>();cs.Push(1);cs.Push(2);cs.Push(3);varclone=newConcurrentStack<int>(cs.DeepClone());// cs pops 3,2,1 ; clone pops 1,2,3varst=newStack<int>();st.Push(1);st.Push(2);st.Push(3);// st.DeepClone() pops 3,2,1 (correct, thanks to the dedicated overload)
Why it matters
The library already treats stack reversal as a bug for Stack<T>, and #94 does the same for ImmutableStack<T>. ConcurrentStack<T> is the remaining BCL LIFO type where it still happens silently. #94 covers only the Immutable* types, so it does not cover this one.
Suggested fix / acceptance criteria
Add public static ConcurrentStack<T> DeepClone<T>(this ConcurrentStack<T> source). Take a ToArray() snapshot first so the clone is consistent under concurrent pushes. Then build from the reversed snapshot with each element deep-cloned, the same way the Stack<T> overload does.
Activity
matt-edmondson commentedon Oct 6, 2026
Triage
Stack<T>.DeepCloneContainerExtensions, as a newConcurrentStack<T>overload.Immutable*types. No open PR covers it.ToArray(), then rebuild from the reversed snapshot, staying NativeAOT-safe per Under NativeAOT, DeepClone over KeyValuePair elements with a value-type key or value throws TypeInitializationException (regression from #82) #92. Add pop-order and deep-reference tests.Generated by Claude Code