diff --git a/src/wren_value.c b/src/wren_value.c index 682b518f..4b18ce6c 100644 --- a/src/wren_value.c +++ b/src/wren_value.c @@ -296,8 +296,9 @@ Value wrenListRemoveAt(WrenVM* vm, ObjList* list, int index) // If we have too much excess capacity, shrink it. if (list->capacity / LIST_GROW_FACTOR >= list->count) { - wrenReallocate(vm, list->elements, sizeof(Value) * list->capacity, - sizeof(Value) * (list->capacity / LIST_GROW_FACTOR)); + list->elements = wrenReallocate(vm, list->elements, + sizeof(Value) * list->capacity, + sizeof(Value) * (list->capacity / LIST_GROW_FACTOR)); list->capacity /= LIST_GROW_FACTOR; } diff --git a/test/list/grow_shrink.wren b/test/list/grow_shrink.wren new file mode 100644 index 00000000..a1e9fd58 --- /dev/null +++ b/test/list/grow_shrink.wren @@ -0,0 +1,11 @@ +// This mostly tests that lists handle growing and shrinking their memory. +var list = [] +for (i in 0..200) { + list.add(i) +} + +for (i in 0..195) { + list.removeAt(-1) +} + +IO.print(list) // expect: [0, 1, 2, 3, 4]