On Saturday, 16 December 2023 at 22:44:16 UTC, Dennis wrote:
That's because `m[f] = 1` initializes the associative array to something non-null. If you pass a `null` AA to a function which adds things, the caller will still have a null pointers.

I've gotten this error in deployed Perl. Whenever the ceremony of creating a data structure is reduced, people can lose sight of when that happens.

Here's a less common gotcha:

```d
void main() {
    import std.stdio : writeln;

    int force_realloc(ref int[] seq) {
        foreach (int i; 1 .. 1_000_000) {
            seq ~= i;
        }
        return 1234;
    }

    int[] a = [4321];
    writeln(a[0]);  // 4321, of course
    a[0] = force_realloc(a);
    writeln(a[0]);  // still 4321
}
```

The `a[0]` on the left of the assignment is decided early, and then force_realloc() changes what the location should be.

Reply via email to