-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
index out of bounds when accessing when accessing an element in an array #21152
Comments
I think whats happening is that |
more specifically:
not sure this is a bug. |
its exhibiting the same failure as pub fn main() !void {
const x = list.items; // { ptr: undefined, len: 0 } is on the stack
const y = try addToList(2); // original list.items is updated
std.debug.print("{}\n", .{x[y]}); // access and print old value
} |
The order of evaluation is working the way I'd expect it to here. |
I think I can see arguments for both evaluation orders: Reading |
Zig Version
0.14.0-dev.1217+dffc8c44f
Steps to Reproduce and Observed Behavior
I apologize for the poor issue title.
Here is a minimal code that produces the error:
Observed behavior:
thread 144618: index out of bounds: index 0, len 0
Expected Behavior
The array access should not fail, since the element exists before it is accessed.
It is even possible to log the length of the array before the panic by putting a block (for instance
blk: { const r = try addToList(2); std.debug.print("len: {}", .{list.items.len}); break :blk r; }
).I am guessing the out of bound detection code takes the length of the array before compute the result of
addToList
The text was updated successfully, but these errors were encountered: