Returning address of local array failed,but returning slice ok

Hi guys,

Have look at the following code

fn bar() []u8 {
    var a: [3]u8 = .{ 1, 2, 3 };
    return &a;
}

this will fail with returning address of expired local variable ‘a’ but return a[0..]; will compile.

I think the compile error regarding this is just not implemented yet. Tracking this issue in hopes of future progress.

1 Like

This will certainly be fixed. But in the end, catching all leaks of the stack (no false negatives) and only leaks of the stack (no false positives) is equivalent to the halting problem. Hopefully most trivial examples like yours will be caught, but there will remain false negatives.

1 Like