mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
`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".
9 lines
182 B
Zig
9 lines
182 B
Zig
test "integer cast panic" {
|
|
var a: u16 = 0xabcd; // runtime-known
|
|
_ = &a;
|
|
const b: u8 = @intCast(a);
|
|
_ = b;
|
|
}
|
|
|
|
// test_error=integer does not fit in destination type
|