#Why am I getting `unreachable` error while sorting?

1 messages · Page 1 of 1 (latest)

vital jacinth
#

I got the following error:

|| test src/ts.zig
|| └─ run test failure
|| thread 3885 panic: reached unreachable code
/usr/lib/zig/std/debug.zig|412 col 14| 0x10f9c6c in assert (test)
||     if (!ok) unreachable; // assertion failure
||              ^
/usr/lib/zig/std/sort/block.zig|110 col 29| 0x111523a in lessThan (test)
||             std.debug.assert(!(lt and gt));
||                             ^
/usr/lib/zig/std/sort/block.zig|1071 col 17| 0x1115777 in swap__anon_6249 (test)
||     if (lessThan(context, items[y], items[x]) or ((order.*)[x] > (order.*)[y] and !lessThan(context, items[x], items[y]))) {
||                 ^
/usr/lib/zig/std/sort/block.zig|210 col 21| 0x11003e9 in block__anon_5086 (test)
||                 swap(T, sliced_items, &order, 1, 3, context, lessThan);
||                     ^
/usr/lib/zig/std/mem.zig|567 col 19| 0x10f9140 in sort__anon_2085 (test)
||     std.sort.block(T, items, context, lessThanFn);
||                   ^
src/ts.zig|93 col 17| 0x10f8627 in test.cmpByRange (test)
||     std.mem.sort(Range, slice, {}, cmpByRange);
||                 ^
/usr/lib/zig/compiler/test_runner.zig|95 col 29| 0x110dcf7 in mainServer (test)
||                 test_fn.func() catch |err| switch (err) {
||                             ^
/usr/lib/zig/compiler/test_runner.zig|35 col 26| 0x10f997e in main (test)
||         return mainServer() catch @panic("internal test runner failure");
||                          ^
/usr/lib/zig/std/start.zig|514 col 22| 0x10f9489 in main (test)
||             root.main();
||                      ^
|| ???:?:?: 0x7d9eb8d3ac87 in ??? (libc.so.6)
|| Unwind information for `libc.so.6:0x7d9eb8d3ac87` was not available, trace may be incomplete
|| 
|| ???:?:?: 0x7d9eb8d3ad4b in ??? (libc.so.6)
|| ???:?:?: 0x10f4364 in ??? (???)
.....
|| [Process exited 1]
#

If I comment these lines out, the asserts will fail but no unreachable error:

    if (a.R < b.R) return true;
    if (a.R == b.R and a.C < b.C) return true;