From 0686e83f4c8fd91c657d3fa5e73a074043474fa7 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Fri, 25 Feb 2022 20:01:11 +0800 Subject: [PATCH] nac3core/typecheck: fixed incorrect rollback --- nac3core/src/typecheck/typedef/mod.rs | 2 ++ nac3core/src/typecheck/unification_table.rs | 1 + 2 files changed, 3 insertions(+) diff --git a/nac3core/src/typecheck/typedef/mod.rs b/nac3core/src/typecheck/typedef/mod.rs index 0af37127..6246dc21 100644 --- a/nac3core/src/typecheck/typedef/mod.rs +++ b/nac3core/src/typecheck/typedef/mod.rs @@ -427,6 +427,7 @@ impl Unifier { let mut all_names: Vec<_> = signature.args.iter().map(|v| (v.name, v.ty)).rev().collect(); for (i, t) in posargs.iter().enumerate() { if signature.args.len() <= i { + self.restore_snapshot(); return Err(TypeError::new( TypeErrorKind::TooManyArguments { expected: signature.args.len(), got: i }, *loc, @@ -483,6 +484,7 @@ impl Unifier { } self.unify_cache.clear(); if self.unification_table.unioned(a, b) { + self.discard_snapshot(snapshot); Ok(()) } else { let result = self.unify_impl(a, b, false); diff --git a/nac3core/src/typecheck/unification_table.rs b/nac3core/src/typecheck/unification_table.rs index 70864154..43ef0637 100644 --- a/nac3core/src/typecheck/unification_table.rs +++ b/nac3core/src/typecheck/unification_table.rs @@ -61,6 +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.parents[b] = a; if self.ranks[a] == self.ranks[b] { self.log.push(Action::Rank { key: a, original_rank: self.ranks[a] });