diff --git a/compiler/noirc_frontend/src/hir/type_check/expr.rs b/compiler/noirc_frontend/src/hir/type_check/expr.rs index e4d3a0be342..c720b87043c 100644 --- a/compiler/noirc_frontend/src/hir/type_check/expr.rs +++ b/compiler/noirc_frontend/src/hir/type_check/expr.rs @@ -1167,6 +1167,10 @@ impl<'interner> TypeChecker<'interner> { match op { crate::UnaryOp::Minus => { + if rhs_type.is_unsigned() { + self.errors + .push(TypeCheckError::InvalidUnaryOp { kind: rhs_type.to_string(), span }); + } let expected = Type::polymorphic_integer(self.interner); rhs_type.unify(&expected, &mut self.errors, || TypeCheckError::InvalidUnaryOp { kind: rhs_type.to_string(), diff --git a/test_programs/compile_failure/negate_unsigned/Nargo.toml b/test_programs/compile_failure/negate_unsigned/Nargo.toml new file mode 100644 index 00000000000..0b5486024c2 --- /dev/null +++ b/test_programs/compile_failure/negate_unsigned/Nargo.toml @@ -0,0 +1,6 @@ +[package] +name = "negate_unsigned" +type = "bin" +authors = [""] + +[dependencies] \ No newline at end of file diff --git a/test_programs/compile_failure/negate_unsigned/Prover.toml b/test_programs/compile_failure/negate_unsigned/Prover.toml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test_programs/compile_failure/negate_unsigned/src/main.nr b/test_programs/compile_failure/negate_unsigned/src/main.nr new file mode 100644 index 00000000000..db5f9b0820f --- /dev/null +++ b/test_programs/compile_failure/negate_unsigned/src/main.nr @@ -0,0 +1,6 @@ +use dep::std; + +fn main() { + let var = -1 as u8; + std::println(var); +}