Skip to content

Commit

Permalink
fix(Inference): Account for self-referencial constraints (#551)
Browse files Browse the repository at this point in the history
Resolves #549
  • Loading branch information
croyzor authored Sep 22, 2023
1 parent bf6ffee commit dbb94d3
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/extension/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,17 @@ impl UnificationContext {
pub fn instantiate_variables(&mut self) {
for m in self.variables.clone().into_iter() {
if !self.solved.contains_key(&m) {
self.add_solution(m, ExtensionSet::new());
// Handle the case where the constraints for `m` contain a self
// reference, i.e. "m = Plus(E, m)", in which case the variable
// should be instantiated to E rather than the empty set.
let solution =
ExtensionSet::from_iter(self.get_constraints(&m).unwrap().iter().filter_map(
|c| match c {
Constraint::Plus(x, other_m) if &m == other_m => Some(x.clone()),
_ => None,
},
));
self.add_solution(m, solution);
}
}
self.variables = HashSet::new();
Expand Down

0 comments on commit dbb94d3

Please sign in to comment.