#Compiler Exits Unexpectedly, No indication to why

1 messages · Page 1 of 1 (latest)

whole plinth
#

I am using the zig 0.15.2
And working in in a personal project.
The project with zig build test works fine but does not zig build has the following ouput:

❯ zig build
install
└─ install BPE
   └─ compile exe BPE Debug native failure
error: the following command terminated unexpectedly:
/usr/bin/zig build-exe -ODebug -Mroot=/mnt/fast/home/sillyprogramming/Project/BPE/src/main.zig --cache-dir .zig-cache --global-cache-dir /home/sillyprogramming/.cache/zig --name BPE --zig-lib-
dir /usr/lib/zig/ --listen=-

Build Summary: 0/3 steps succeeded; 1 failed
install transitive failure
└─ install BPE transitive failure
   └─ compile exe BPE Debug native failure

error: the following build command failed with exit code 1:
.zig-cache/o/f173c1364850ca79c2a2aba7c62af021/build /usr/bin/zig /usr/lib/zig /mnt/fast/home/sillyprogramming/Project/BPE .zig-cache /home/sillyprogramming/.cache/zig --seed 0xd1035e06 -Z18cb2
32485fc9652

Here is the project https://github.com/EvilAlliance/BPE

Is my build.zig wrong, or what are the red flags that could cause this?

GitHub

Byte Pair Encoding as a Compression Algorithm. Contribute to EvilAlliance/BPE development by creating an account on GitHub.

#

If I comment out line 21 of main the build works, so i suppouse the build.zig is okey and the problem is inside the iterate function in main.zig

#

seems the proble is here,

fn getToken(dic: *Dic, r: *io.Reader) !?T {
            const first = r.takeByte() catch |err| switch (err) {
                error.EndOfStream => return null,
                else => return @errorCast(err),
            };

            var right = dic.getChar(first) orelse return first;

            while (r.peekByte() catch return right.getValue() orelse first) |peeked| {
                const next = right.getChar(peeked) orelse break;
                assert(next.getValue() != null);
                _ = r.takeByte();
                right = next;
            }

            return right.getValue() orelse first;
        }

If i have to bet the problem is the while condition

exotic wren
#

my guess is the errorCast

#

the function has an inferred error set so it probably doesnt know what its meant to cast to and theres a missing check in the compiler

#

yeah that was it, do this instead

const first = r.takeByte() catch |err| switch (err) {
    error.EndOfStream => return null,
    else => |e| return e,
};

the |e| is a narrowed error set that only contains the errors that are part of the else

whole plinth
#

But the compile could not tell me this error?
Seems silly

#

ty

exotic wren