diff --git a/compiler/noirc_frontend/src/ast/mod.rs b/compiler/noirc_frontend/src/ast/mod.rs index d4c48466b85..f39832e22b3 100644 --- a/compiler/noirc_frontend/src/ast/mod.rs +++ b/compiler/noirc_frontend/src/ast/mod.rs @@ -43,8 +43,11 @@ use crate::{ use acvm::acir::AcirField; use iter_extended::vecmap; +use strum::IntoEnumIterator; +use strum_macros::EnumIter; + #[cfg_attr(test, derive(Arbitrary))] -#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Ord, PartialOrd)] +#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash, Ord, PartialOrd, EnumIter)] pub enum IntegerBitSize { One, Eight, @@ -69,7 +72,7 @@ impl IntegerBitSize { impl IntegerBitSize { pub fn allowed_sizes() -> Vec { - vec![Self::One, Self::Eight, Self::ThirtyTwo, Self::SixtyFour] + IntegerBitSize::iter().collect() } } diff --git a/compiler/noirc_frontend/src/tests.rs b/compiler/noirc_frontend/src/tests.rs index 62da755887b..8fd292aab75 100644 --- a/compiler/noirc_frontend/src/tests.rs +++ b/compiler/noirc_frontend/src/tests.rs @@ -4146,3 +4146,15 @@ fn immutable_references_without_ownership_feature() { "#; check_errors(src); } + +#[test] +fn errors_on_invalid_integer_bit_size() { + let src = r#" + fn main() { + let _: u42 = 4; + ^^^ Use of invalid bit size 42 + ~~~ Allowed bit sizes for integers are 1, 8, 16, 32, 64, 128 + } + "#; + check_errors(src); +}