From d9be8d3978f01e0651a344eb7b10e884dd4991bc Mon Sep 17 00:00:00 2001 From: pca006132 Date: Wed, 23 Mar 2022 00:23:26 +0800 Subject: [PATCH] nac3core/typecheck/unification_table: fixed snapshot restore bug Closes 229 --- nac3core/src/typecheck/unification_table.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/nac3core/src/typecheck/unification_table.rs b/nac3core/src/typecheck/unification_table.rs index 43ef06375..101057c5e 100644 --- a/nac3core/src/typecheck/unification_table.rs +++ b/nac3core/src/typecheck/unification_table.rs @@ -61,7 +61,7 @@ impl UnificationTable { if self.ranks[a] < self.ranks[b] { std::mem::swap(&mut a, &mut b); } - self.log.push(Action::Parent { key: b, original_parent: a }); + self.log.push(Action::Parent { key: b, original_parent: self.parents[b] }); self.parents[b] = a; if self.ranks[a] == self.ranks[b] { self.log.push(Action::Rank { key: a, original_rank: self.ranks[a] }); @@ -106,7 +106,7 @@ impl UnificationTable { // a = parent.parent let a = self.parents[parent]; // root.parent = parent.parent - self.log.push(Action::Parent { key: root, original_parent: a }); + self.log.push(Action::Parent { key: root, original_parent: self.parents[root] }); self.parents[root] = a; root = parent; // parent = root.parent @@ -145,8 +145,8 @@ impl UnificationTable { pub fn discard_snapshot(&mut self, snapshot: (usize, u32)) { let (log_len, generation) = snapshot; assert!(self.log.len() >= log_len, "snapshot discard error"); - assert!(matches!(self.log[log_len - 1], Action::Marker { generation: gen } if generation == gen), "snapshot discard error"); - self.log.truncate(log_len - 1); + assert!(matches!(self.log[log_len - 1], Action::Marker { generation: gen } if gen == generation), "snapshot discard error"); + self.log.clear(); } }