Skip to content

Commit

Permalink
Fix expected range where end - start = 2^n - 1.
Browse files Browse the repository at this point in the history
  • Loading branch information
finnbear committed Jul 29, 2023
1 parent 1140b87 commit 59b1cad
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/encoding/expected_range_u64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl<const MIN: u64, const MAX: u64> ExpectedRangeU64<MIN, MAX> {
if Self::RANGE.is_power_of_two() {
None
} else {
Some(Self::RANGE + 1)
Some(Self::RANGE)
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,3 +543,18 @@ fn test_fixed_size_array() {
the_same([1u64, 2, 3, 4, 5, 6, 7, 8]);
the_same([0u8; 19]);
}

#[test]
fn expected_range_bug() {
#[derive(Encode, Decode, Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct UVec2 {
x: u16,
y: u16,
}

#[derive(Encode, Decode, Serialize, Deserialize, PartialEq, Debug, Clone)]
pub struct Wrapper(#[bitcode_hint(expected_range = "0..31")] UVec2);

let val = Wrapper(UVec2 { x: 500, y: 512 });
the_same(val);
}

0 comments on commit 59b1cad

Please sign in to comment.