zig/test/cases/safety/@intCast to u0.zig
mlugg c1a5caa454
compiler: combine @intCast safety checks
`castTruncatedData` was a poorly worded error (all shrinking casts
"truncate bits", it's just that we assume those bits to be zext/sext of
the other bits!), and `negativeToUnsigned` was a pointless distinction
which forced the compiler to emit worse code (since two separate safety
checks were required for casting e.g. 'i32' to 'u16') and wasn't even
implemented correctly. This commit combines those safety panics into one
function, `integerOutOfBounds`. The name maybe isn't perfect, but that's
not hugely important; what matters is the new default message, which is
clearer than the old ones: "integer does not fit in destination type".
2025-06-01 12:10:57 +01:00

23 lines
496 B
Zig

const std = @import("std");
pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
_ = stack_trace;
if (std.mem.eql(u8, message, "integer does not fit in destination type")) {
std.process.exit(0);
}
std.process.exit(1);
}
pub fn main() !void {
bar(1, 1);
return error.TestFailed;
}
fn bar(one: u1, not_zero: i32) void {
const x = one << @intCast(not_zero);
_ = x;
}
// run
// backend=stage2,llvm
// target=native