From a92fd10b8e88f68f9a2e3dad96f8d5efe5365cc6 Mon Sep 17 00:00:00 2001 From: Tom French Date: Tue, 27 Feb 2024 23:29:43 +0000 Subject: [PATCH] chore: small refactor --- compiler/noirc_frontend/src/hir/type_check/stmt.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/compiler/noirc_frontend/src/hir/type_check/stmt.rs b/compiler/noirc_frontend/src/hir/type_check/stmt.rs index d644891a5b0..cf80ce7fcb5 100644 --- a/compiler/noirc_frontend/src/hir/type_check/stmt.rs +++ b/compiler/noirc_frontend/src/hir/type_check/stmt.rs @@ -306,11 +306,14 @@ impl<'interner> TypeChecker<'interner> { let expr_span = self.interner.expr_span(&stmt.0); // Must type check the assertion message expression so that we instantiate bindings - // We always allow unsafe calls for assert messages as these may be a dynamic assert message call. - let old_allow_unsafe = self.allow_unsafe; - self.allow_unsafe = true; - stmt.2.map(|assert_msg_expr| self.check_expression(&assert_msg_expr)); - self.allow_unsafe = old_allow_unsafe; + if let Some(assert_msg_expr) = stmt.2 { + // We always allow unsafe calls for assert messages as these may be a dynamic assert message call. + // We then must restore the original value however. + let old_allow_unsafe = self.allow_unsafe; + self.allow_unsafe = true; + self.check_expression(&assert_msg_expr); + self.allow_unsafe = old_allow_unsafe; + }; self.unify(&expr_type, &Type::Bool, || TypeCheckError::TypeMismatch { expr_typ: expr_type.to_string(),