# W8001 copy_on_write

URL: /docs/errors/W8001
Markdown: /docs/errors/W8001.md

> An update to a shared collection is forced to copy inside a loop because another reference retains the old value (design §8.2).

A warning from the `package` phase. `sakura explain W8001` prints this explanation offline.

An update to a shared collection is forced to copy inside a loop because another reference
retains the old value (design §8.2). Drop the retaining use or restructure the loop. The code is
registered ahead of its check, which comes with the native backend's reuse analysis (M5); no
command reports it yet.

## Wrong program [#wrong-program]

[`compiler/tests/ui/W8001_copy_on_write.sakura`](https://github.com/icantcodefyi/sakuralang/blob/master/compiler/tests/ui/W8001_copy_on_write.sakura), which the compiler's ui suite does not run yet (needs: native backend with Perceus reuse analysis):

```sakura
fn grow() -> List<Int> {
  var xs = [1]
  var kept = xs
  for i in 0..100 {
    kept = xs
    xs = List.push(xs, i)
  }
  xs
}
```

## Fixed program [#fixed-program]

No fixed program is checked in for this code yet; the explanation above describes the repair.
