From d4721db4a3ce73984b9c09263ee2813fbf63026f Mon Sep 17 00:00:00 2001 From: CrescentonC Date: Tue, 3 Aug 2021 09:45:39 +0800 Subject: [PATCH] not creating temp for borrow, more concise code --- nac3core/src/typecheck/typedef/mod.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs index dbe739d10..37adb67fa 100644 --- a/nac3core/src/typecheck/typedef/mod.rs +++ b/nac3core/src/typecheck/typedef/mod.rs @@ -373,9 +373,8 @@ impl Unifier { (TVar { meta: Record(map), id, range, .. }, TObj { fields, .. }) => { self.occur_check(a, b)?; for (k, v) in map.borrow().iter() { - let temp = fields.borrow(); - let ty = temp.get(k).ok_or_else(|| format!("No such attribute {}", k))?; - self.unify(*ty, *v)?; + let ty = fields.borrow().get(k).copied().ok_or_else(|| format!("No such attribute {}", k))?; + self.unify(ty, *v)?; } let x = self.check_var_compatibility(*id, b, &range.borrow())?.unwrap_or(b); self.unify(x, b)?; @@ -386,12 +385,11 @@ impl Unifier { let ty = self.get_ty(*ty); if let TObj { fields, .. } = ty.as_ref() { for (k, v) in map.borrow().iter() { - let temp = fields.borrow(); - let ty = temp.get(k).ok_or_else(|| format!("No such attribute {}", k))?; - if !matches!(self.get_ty(*ty).as_ref(), TFunc { .. }) { + let ty = fields.borrow().get(k).copied().ok_or_else(|| format!("No such attribute {}", k))?; + if !matches!(self.get_ty(ty).as_ref(), TFunc { .. }) { return Err(format!("Cannot access field {} for virtual type", k)); } - self.unify(*v, *ty)?; + self.unify(*v, ty)?; } } else { // require annotation...