diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs
index 33cda9db0..25a2251ac 100644
--- a/nac3core/src/typecheck/typedef/mod.rs
+++ b/nac3core/src/typecheck/typedef/mod.rs
@@ -204,7 +204,7 @@ impl Unifier {
}
for v1 in old_range2.iter() {
for v2 in range1.iter() {
- if let Ok(result) = self.shape_match(*v1, *v2){
+ if let Ok(result) = self.get_intersection(*v1, *v2){
range2.push(result.unwrap_or(*v2));
}
}
@@ -219,8 +219,9 @@ impl Unifier {
}
(TVar { meta: Generic, id, range, .. }, _) => {
self.occur_check(a, b)?;
- self.check_var_compatible(*id, b, &range.borrow())?;
- self.set_a_to_b(a, b);
+ let x = self.check_var_compatibility(*id, b, &range.borrow())?.unwrap_or(b);
+ self.unify(x, b)?;
+ self.set_a_to_b(a, x);
}
(TVar { meta: Sequence(map), id, range, .. }, TTuple { ty }) => {
self.occur_check(a, b)?;
@@ -236,16 +237,18 @@ impl Unifier {
}
self.unify(*v, ty[ind as usize])?;
}
- self.check_var_compatible(*id, b, &range.borrow())?;
- self.set_a_to_b(a, b);
+ let x = self.check_var_compatibility(*id, b, &range.borrow())?.unwrap_or(b);
+ self.unify(x, b)?;
+ self.set_a_to_b(a, x);
}
(TVar { meta: Sequence(map), id, range, .. }, TList { ty }) => {
self.occur_check(a, b)?;
for v in map.borrow().values() {
self.unify(*v, *ty)?;
}
- self.check_var_compatible(*id, b, &range.borrow())?;
- self.set_a_to_b(a, b);
+ let x = self.check_var_compatibility(*id, b, &range.borrow())?.unwrap_or(b);
+ self.unify(x, b)?;
+ self.set_a_to_b(a, x);
}
(TTuple { ty: ty1 }, TTuple { ty: ty2 }) => {
if ty1.len() != ty2.len() {
@@ -273,8 +276,9 @@ impl Unifier {
return Err(format!("No such attribute {}", k));
}
}
- self.check_var_compatible(*id, b, &range.borrow())?;
- self.set_a_to_b(a, b);
+ let x = self.check_var_compatibility(*id, b, &range.borrow())?.unwrap_or(b);
+ self.unify(x, b)?;
+ self.set_a_to_b(a, x);
}
(TVar { meta: Record(map), id, range, .. }, TVirtual { ty }) => {
self.occur_check(a, b)?;
@@ -294,8 +298,9 @@ impl Unifier {
// require annotation...
return Err("Requires type annotation for virtual".to_string());
}
- self.check_var_compatible(*id, b, &range.borrow())?;
- self.set_a_to_b(a, b);
+ let x = self.check_var_compatibility(*id, b, &range.borrow())?.unwrap_or(b);
+ self.unify(x, b)?;
+ self.set_a_to_b(a, x);
}
(
TObj { obj_id: id1, params: params1, .. },
@@ -647,7 +652,7 @@ impl Unifier {
Ok(())
}
- fn shape_match(&mut self, a: Type, b: Type) -> Result