Tests fail for i32 when value is -1
Hi! I'm currently working on integrating this with https://github.com/archSeer/enigma/
Tests seem to fail on debug_assert!(b.tag() == u32::from(tag), "{} == {}", b.tag(), tag);, because tag() returns 15. I added this quickcheck test to the test suite that seems to always reproduce it:
fn nanbox_i32(tag: u8, v: i32) -> TestResult {
if tag == 0 || tag >= 8 {
return TestResult::discard();
}
unsafe {
TestResult::from_bool(NanBox::new(tag, v).tag() == tag as u32)
}
}
I'm currently looking into this -- it seems like one of the bit shifts might be off
I want to remember that someone pointed out that I got sign extension wrong somewhere. So that might be the cause. Haven't remembered to look into it though.
I think I figured it out: when directly resizing i32 into u64, rust will sign extend it; whereas converting to u32 first, then u64 will work fine:
fn main(){
println!("{:#066b}", -1 as i32);
println!("{:#066b}", -1 as i32 as u32 as u64);
}
0b1111111111111111111111111111111111111111111111111111111111111111
0b0000000000000000000000000000000011111111111111111111111111111111