Skip to content

Commit 70bd41d

Browse files
authored
fix #13310, Deque misbehaves on VM (#13625)
* fix #13310, Deque misbehaves on VM * use 'when nimVM'
1 parent 281e02f commit 70bd41d

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

lib/pure/collections/deques.nim

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,9 @@ proc expandIfNeeded[T](deq: var Deque[T]) =
274274
if unlikely(deq.count >= cap):
275275
var n = newSeq[T](cap * 2)
276276
var i = 0
277-
for x in mitems(deq): # don't use copyMem because of the GC and because it's slower.
278-
n[i] = move(x)
277+
for x in mitems(deq):
278+
when nimVM: n[i] = x # workaround for VM bug
279+
else: n[i] = move(x)
279280
inc i
280281
deq.data = move(n)
281282
deq.mask = cap * 2 - 1
@@ -569,3 +570,15 @@ when isMainModule:
569570
foo(2, 1)
570571
foo(1, 5)
571572
foo(3, 2)
573+
574+
import sets
575+
block t13310:
576+
proc main() =
577+
var q = initDeque[HashSet[int16]](2)
578+
q.addFirst([1'i16].toHashSet)
579+
q.addFirst([2'i16].toHashSet)
580+
q.addFirst([3'i16].toHashSet)
581+
assert $q == "[{3}, {2}, {1}]"
582+
583+
static:
584+
main()

0 commit comments

Comments
 (0)