Skip to content

Commit f7727ef

Browse files
authored
fix(stdlib): Properly resize empty Queue on push (#1865)
1 parent e8cb932 commit f7727ef

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/test/stdlib/queue.test.gr

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ assert Queue.pop(queue) == Some(1)
4747
assert Queue.pop(queue) == Some(2)
4848
assert Queue.pop(queue) == Some(3)
4949
assert Queue.pop(queue) == None
50+
let queue = Queue.makeSized(0)
51+
Queue.push(0, queue)
52+
let queue2 = Queue.makeSized(1)
53+
Queue.push(0, queue2)
54+
assert queue == queue2
5055

5156
// test that the "circular" behavior of the circular queue works as expected
5257
let queue = Queue.makeSized(4)

stdlib/queue.gr

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ provide let peek = queue => {
9494
provide let push = (value, queue) => {
9595
let arrLen = Array.length(queue.array)
9696
// expand the array if needed
97-
if (queue.size == arrLen) {
97+
if (arrLen == 0) {
98+
queue.array = Array.make(1, None)
99+
} else if (queue.size == arrLen) {
98100
let newArray = Array.make(arrLen * 2, None)
99101

100102
newArray[0] = queue.array[queue.headIndex]

0 commit comments

Comments
 (0)