From 4dc5dbb856324cd89a007bd62cd77cdaae781141 Mon Sep 17 00:00:00 2001 From: David Mak Date: Wed, 6 Dec 2023 11:05:42 +0800 Subject: [PATCH] meta: Replace equality assertion with assert_eq Emits a more useful assertion message. --- nac3core/build.rs | 2 +- nac3core/src/codegen/expr.rs | 2 +- nac3core/src/toplevel/composer.rs | 3 +-- nac3core/src/typecheck/typedef/test.rs | 10 +++++----- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/nac3core/build.rs b/nac3core/build.rs index c747274bd..f7e7e92df 100644 --- a/nac3core/build.rs +++ b/nac3core/build.rs @@ -44,7 +44,7 @@ fn main() { let regex_filter = Regex::new(r"(?ms:^define.*?\}$)|(?m:^declare.*?$)").unwrap(); for f in regex_filter.captures_iter(&output) { - assert!(f.len() == 1); + assert_eq!(f.len(), 1); filtered_output.push_str(&f[0]); filtered_output.push('\n'); } diff --git a/nac3core/src/codegen/expr.rs b/nac3core/src/codegen/expr.rs index 30aa2e3f8..83c29caa3 100644 --- a/nac3core/src/codegen/expr.rs +++ b/nac3core/src/codegen/expr.rs @@ -1165,7 +1165,7 @@ pub fn gen_binop_expr<'ctx, 'a, G: CodeGenerator>( Ok(Some(ctx.gen_float_ops(op, left_val, right_val).into())) } else if ty1 == ctx.primitives.float && ty2 == ctx.primitives.int32 { // Pow is the only operator that would pass typecheck between float and int - assert!(*op == Operator::Pow); + assert_eq!(*op, Operator::Pow); let i32_t = ctx.ctx.i32_type(); let pow_intr = ctx.module.get_function("llvm.powi.f64.i32").unwrap_or_else(|| { let f64_t = ctx.ctx.f64_type(); diff --git a/nac3core/src/toplevel/composer.rs b/nac3core/src/toplevel/composer.rs index f1de1073a..781c2ef6d 100644 --- a/nac3core/src/toplevel/composer.rs +++ b/nac3core/src/toplevel/composer.rs @@ -102,12 +102,11 @@ impl TopLevelComposer { if *func_name != simple_name.to_string() { continue } - builtin_ty.insert(name, *signature); builtin_id.insert(name, DefinitionId(id)); } else if let TopLevelDef::Class { name, constructor, object_id, .. } = &*def { - assert!(id == object_id.0); + assert_eq!(id, object_id.0); if let Some(constructor) = constructor { builtin_ty.insert(*name, *constructor); } diff --git a/nac3core/src/typecheck/typedef/test.rs b/nac3core/src/typecheck/typedef/test.rs index cd3a22d8f..0762a10ef 100644 --- a/nac3core/src/typecheck/typedef/test.rs +++ b/nac3core/src/typecheck/typedef/test.rs @@ -139,7 +139,7 @@ impl TestEnvironment { match &typ[..end] { "tuple" => { let mut s = &typ[end..]; - assert!(&s[0..1] == "["); + assert_eq!(&s[0..1], "["); let mut ty = Vec::new(); while &s[0..1] != "]" { let result = self.internal_parse(&s[1..], mapping); @@ -149,14 +149,14 @@ impl TestEnvironment { (self.unifier.add_ty(TypeEnum::TTuple { ty }), &s[1..]) } "list" => { - assert!(&typ[end..end + 1] == "["); + assert_eq!(&typ[end..end + 1], "["); let (ty, s) = self.internal_parse(&typ[end + 1..], mapping); - assert!(&s[0..1] == "]"); + assert_eq!(&s[0..1], "]"); (self.unifier.add_ty(TypeEnum::TList { ty }), &s[1..]) } "Record" => { let mut s = &typ[end..]; - assert!(&s[0..1] == "["); + assert_eq!(&s[0..1], "["); let mut fields = HashMap::new(); while &s[0..1] != "]" { let eq = s.find('=').unwrap(); @@ -176,7 +176,7 @@ impl TestEnvironment { let te = self.unifier.get_ty(ty); if let TypeEnum::TObj { params, .. } = &*te.as_ref() { if !params.is_empty() { - assert!(&s[0..1] == "["); + assert_eq!(&s[0..1], "["); let mut p = Vec::new(); while &s[0..1] != "]" { let result = self.internal_parse(&s[1..], mapping);