# no-array-fill-with-reference-type

Disallow Array.fill values that share mutable references

`Array.fill` places the same managed reference in every selected element, so later mutation is shared by all of them.
Instead, you SHOULD construct each mutable value independently with `Array.from` or an explicit loop.

- Category: suspicious
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
class Cell {
    value: int32 = 0;
}

function cells(): Cell[] {
    const values = [new Cell(), new Cell(), new Cell()];
    values.fill(new Cell());
    return values;
}
```

## Accepted

```ds title="main.ds"
class Cell {
    value: int32 = 0;
}

function cells(): Cell[] {
    return [new Cell(), new Cell(), new Cell()];
}
```

## Prior art

- [eslint-plugin-unicorn · no-array-fill-with-reference-type](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-array-fill-with-reference-type.md)

[language/linter/src/rules/suspicious/no_array_fill_with_reference_type.rs:6](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/suspicious/no_array_fill_with_reference_type.rs#L6)
