Skip to content

Commit

Permalink
Merge branch 'main' into move-out-executable
Browse files Browse the repository at this point in the history
  • Loading branch information
vsbogd authored Jun 15, 2024
2 parents 57ecd88 + 9019fac commit 3727042
Showing 1 changed file with 24 additions and 3 deletions.
27 changes: 24 additions & 3 deletions lib/src/atom/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,8 +736,17 @@ impl Bindings {
Atom::Variable(var) => {
if to_remove.contains(&var) {
match self.resolve(var) {
Some(Atom::Variable(v)) if to_remove.contains(&v) => { self.rename_var(var, &to_remove).map(|v| *atom = v); },
Some(value) => { *atom = value; },
Some(mut value) => {
value.iter_mut().for_each(|atom| match atom {
Atom::Variable(var) if to_remove.contains(&var) => {
self.rename_var(var, &to_remove).map(|var| {
*atom = var;
});
},
_ => {},
});
*atom = value;
},
None => {},
}
}
Expand Down Expand Up @@ -1792,7 +1801,7 @@ mod test {
.add_var_equality(&VariableAtom::new("a"), &VariableAtom::new("b"))?;
bindings.apply_and_retain(&mut atom, |_| false);
assert!(bindings.is_empty());
assert_eq!(atom, expr!(a b));
assert_eq!(atom, expr!(a a));
Ok(())
}

Expand All @@ -1806,6 +1815,18 @@ mod test {
Ok(())
}

#[test]
fn bindings_retain_apply_wiped_variable() -> Result<(), &'static str> {
let mut atom = expr!(b);
let mut bindings = Bindings::new()
.add_var_equality(&VariableAtom::new("a"), &VariableAtom::new("retained"))?
.add_var_binding_v2(&VariableAtom::new("b"), expr!((a)))?;
bindings.apply_and_retain(&mut atom, |v| *v == VariableAtom::new("retained"));
assert_eq!(bindings, bind!{ retained: expr!(retained) });
assert_eq!(atom, expr!((retained)));
Ok(())
}

#[test]
fn bindings_rename_binding() -> Result<(), &'static str> {
let a = &VariableAtom::new("a");
Expand Down

0 comments on commit 3727042

Please sign in to comment.