zig icon indicating copy to clipboard operation
zig copied to clipboard

Incremental compilation doesn't fail on wrong source when incorrectly narrowing a return error set

Open Zirunis opened this issue 1 month ago • 1 comments

Zig Version

0.16.0-dev.1246+4b593a6c2

Steps to Reproduce and Observed Behavior

Correct code:

const std = @import("std");

pub fn main() !void {
    try std.testing.expect(2 + 2 == 5);
}

zig build --watch -fincremental successfully builds the excecutable.

Change the code to be wrong:

const std = @import("std");

pub fn main() void {  //not declaring the error set anymore!
    try std.testing.expect(2 + 2 == 5);
}

zig build --watch -fincremental claims successful compilation (3/3 build steps). It does not alert to the error. But it does also not miscompile, in fact it leaves the previous executable untouched.

Expected Behavior

Incremental compilation should be equivalent to running zig build again. In this case that means it should notify the user that compilation failed and point out the error.

Related: #25873

Zirunis avatar Nov 09 '25 01:11 Zirunis

@mlugg You probably made the connection, but just to make sure: This was also on windows and therefore with the llvm-backend. I'll see if I can reproduce it using the self-hosted backend tomorrow to make sure this actually happens in a supported use-case.

Zirunis avatar Nov 10 '25 02:11 Zirunis

I did indeed figure that this was with the LLVM backend, but I suspect there could be an actual bug here, because compile errors should happen correctly irrespective of the backend in use. I haven't gotten around to testing if this repros with -fno-llvm or -fno-emit-bin yet. You don't need to do that, but if you do, then yeah, let me know what happens; thanks!

mlugg avatar Nov 10 '25 11:11 mlugg

Hm, it actually seems like using the LLVM backend does cause this bug; I can repro it with use_llvm = true, but not when using the x86 backend. That's a little surprising! So, I'll close this one too, but thanks for the report.

mlugg avatar Nov 10 '25 12:11 mlugg