forked from M-Labs/nac3
1
0
Fork 0

nac3core/typecheck: fixed incorrect rollback

This commit is contained in:
pca006132 2022-02-25 20:01:11 +08:00
parent e710b6c320
commit 0686e83f4c
2 changed files with 3 additions and 0 deletions

View File

@ -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);

View File

@ -61,6 +61,7 @@ impl<V> UnificationTable<V> {
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] });