From c2d00aa762cd08dcc4f71ab52fe41d1ef5df6a9e Mon Sep 17 00:00:00 2001 From: pca006132 Date: Thu, 15 Jul 2021 16:51:55 +0800 Subject: [PATCH] occur check --- nac3core/src/typecheck/test_typedef.rs | 7 +++++++ nac3core/src/typecheck/typedef.rs | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/nac3core/src/typecheck/test_typedef.rs b/nac3core/src/typecheck/test_typedef.rs index 4eeb1cd8..f411f689 100644 --- a/nac3core/src/typecheck/test_typedef.rs +++ b/nac3core/src/typecheck/test_typedef.rs @@ -242,6 +242,13 @@ mod test { (("v1", "v2"), "No such attribute b") ; "record obj merge" )] + #[test_case(2, + &[ + ("v1", "List[v2]"), + ], + (("v1", "v2"), "Recursive type is prohibited.") + ; "recursive type for lists" + )] fn test_invalid_unification( variable_count: u32, unify_pairs: &[(&'static str, &'static str)], diff --git a/nac3core/src/typecheck/typedef.rs b/nac3core/src/typecheck/typedef.rs index 03b3ae28..645a96bc 100644 --- a/nac3core/src/typecheck/typedef.rs +++ b/nac3core/src/typecheck/typedef.rs @@ -216,7 +216,7 @@ impl Unifier { drop(ty_b); if let TypeEnum::TSeq { map: map2 } = &mut *ty_b_cell.as_ref().borrow_mut() { - // unify them to map1 + // unify them to map2 for (key, value) in map1.iter() { if let Some(ty) = map2.get(key) { self.unify(*ty, *value)?; @@ -377,7 +377,7 @@ impl Unifier { fn occur_check(&self, a: TypeIndex, b: Type) -> Result<(), String> { let i_b = self.unification_table.borrow_mut().probe_value(b); if a == i_b { - return Err("Recursive type detected!".to_owned()); + return Err("Recursive type is prohibited.".to_owned()); } let ty = self.type_arena.borrow().get(i_b.0).unwrap().clone(); let ty = ty.borrow();