When I use an invalid range like 2..1 in a for loop, the error I get is something like
src/main.zig:42:11: error: overflow of integer type 'usize' with value '-1'
Why is this the case?
When I use an invalid range like 2..1 in a for loop, the error I get is something like
src/main.zig:42:11: error: overflow of integer type 'usize' with value '-1'
Why is this the case?
I think it’s a bug, I couldn’t find an existing issue so you should make one, dont forget they moved to codeberg
I wasnt sure if a decreasing range is supported, but it looks like its not.
Either way, I think it’s a bug. The compiler should insert a safety check for the range bounds instead of having an overflow (imo).
Thanks, created one here.
found the relevant issue Better error message when `start` is bigger than the `end` in `for(start..end)` · Issue #14701 · ziglang/zig · GitHub