diff --git a/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify/cast.rs b/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify/cast.rs index 11b849cc5fa..3cf6f10ddaa 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify/cast.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/dfg/simplify/cast.rs @@ -17,6 +17,11 @@ pub(super) fn simplify_cast( dfg: &mut DataFlowGraph, ) -> SimplifyResult { use SimplifyResult::*; + debug_assert!( + dfg.type_of_value(value).is_numeric(), + "Can only cast numeric types, got {:?}", + dfg.type_of_value(value) + ); if Type::Numeric(dst_typ) == dfg.type_of_value(value) { return SimplifiedTo(value); diff --git a/compiler/noirc_evaluator/src/ssa/ir/types.rs b/compiler/noirc_evaluator/src/ssa/ir/types.rs index 1c1b5967aff..ce9f7185d5f 100644 --- a/compiler/noirc_evaluator/src/ssa/ir/types.rs +++ b/compiler/noirc_evaluator/src/ssa/ir/types.rs @@ -191,6 +191,11 @@ impl Type { Type::unsigned(SSA_WORD_SIZE) } + /// True if this type is a numeric primitive type. + pub(crate) fn is_numeric(&self) -> bool { + matches!(self, Type::Numeric(_)) + } + /// Returns the inner NumericType if this is one, or panics otherwise pub(crate) fn unwrap_numeric(&self) -> NumericType { match self { diff --git a/test_programs/execution_panic/regression_9986/Nargo.toml b/test_programs/execution_panic/regression_9986/Nargo.toml new file mode 100644 index 00000000000..e3357d2adcd --- /dev/null +++ b/test_programs/execution_panic/regression_9986/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "regression_9986" +type = "bin" +authors = [""] + +[dependencies] \ No newline at end of file diff --git a/test_programs/execution_panic/regression_9986/src/main.nr b/test_programs/execution_panic/regression_9986/src/main.nr new file mode 100644 index 00000000000..f00437c5efb --- /dev/null +++ b/test_programs/execution_panic/regression_9986/src/main.nr @@ -0,0 +1,3 @@ +fn main() { + [("", 0_u32)][2147483648].1 == 0; +} \ No newline at end of file