diff --git a/crates/compiler/builtins/bitcode/src/list.zig b/crates/compiler/builtins/bitcode/src/list.zig index eef76bfbaf..37d29fbe1d 100644 --- a/crates/compiler/builtins/bitcode/src/list.zig +++ b/crates/compiler/builtins/bitcode/src/list.zig @@ -740,9 +740,11 @@ fn swapElements(source_ptr: [*]u8, element_width: usize, index_1: usize, index_2 } pub fn listConcat(list_a: RocList, list_b: RocList, alignment: u32, element_width: usize) callconv(.C) RocList { - if (list_a.isEmpty()) { - return list_b; - } else if (list_b.isEmpty()) { + // NOTE we always use list_a! because it is owned, we must consume it, and it may have unused capacity + if (list_b.isEmpty()) { + // we must consume this list. Even though it has no elements, it could still have capacity + list_b.deinit(usize); + return list_a; } else if (list_a.isUnique()) { const total_length: usize = list_a.len() + list_b.len();