zig
zig copied to clipboard
Incremental compilation fails for valid source when correctly widening the return error set
Zig Version
0.16.0-dev.1246+4b593a6c2
Steps to Reproduce and Observed Behavior
Wrong code:
const std = @import("std");
pub fn main() void { //no error set declared here!
try std.testing.expect(2 + 2 == 5);
}
zig build --watch -fincremental correctly points out the error:
src\main.zig:4:5: error: expected type 'void', found '@typeInfo(@typeInfo(@TypeOf(testing.expect)).@"fn".return_type.?).error_union.error_set'
try std.testing.expect(2 + 2 == 5);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src\main.zig:3:15: note: function cannot return an error
pub fn main() void {
^~~~
Fix the code:
const std = @import("std");
pub fn main() !void { //now correct
try std.testing.expect(2 + 2 == 5);
}
zig build --watch -fincremental incorrectly throws an error despite the source being valid:
error: Found return instr that returns non-void in Function of void return type!
ret i16 %1, !dbg !50393
voidFound return instr that returns non-void in Function of void return type!
ret i16 0, !dbg !50393
voidLLVM ERROR: Broken module found, compilation aborted!
error: process exited with error code 9
Expected Behavior
Incremental compilation should lead to an equivalent result as running zig build again. In this case that means building successfully.
Related: #25874