Files
zig/test/cases/compile_errors/sub_on_undefined_value.zig
Techatrix ec358d6db5 sema: fix safe integer arithmetic operations on undefined values
Previously `@as(i64, undefined) +% 1` would produce `@as(@TypeOf(undefined), undefined)` which now gives `@as(i64, undefined)`.
Previously `@as(i64, undefined) +| 1` would hit an assertion which now gives `@as(i64, undefined)`.
2024-01-16 16:27:31 -08:00

21 lines
435 B
Zig

comptime {
const undef: i64 = undefined;
const not_undef: i64 = 32;
// If the rhs is zero, then the other operand is returned, even if it is undefined.
@compileLog(undef - 0);
@compileLog(not_undef - 0);
_ = undef - undef;
}
// error
// backend=stage2
// target=native
//
// :9:17: error: use of undefined value here causes undefined behavior
//
// Compile Log Output:
// @as(i64, undefined)
// @as(i64, 32)