Skip to content

Commit

Permalink
Fix occurs check
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Jul 17, 2024
1 parent 30cb65a commit 1286bbe
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions compiler/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,9 @@ impl TypeVariable {
/// variable is already bound to a different type. This generally
/// a logic error to use outside of monomorphization.
pub fn force_bind(&self, typ: Type) {
*self.1.borrow_mut() = TypeBinding::Bound(typ);
if !typ.occurs(self.id()) {
*self.1.borrow_mut() = TypeBinding::Bound(typ);
}
}
}

Expand Down Expand Up @@ -1924,9 +1926,11 @@ impl Type {
generic_args.iter().any(|arg| arg.occurs(target_id))
}
Type::Tuple(fields) => fields.iter().any(|field| field.occurs(target_id)),
Type::NamedGeneric(binding, _, _) | Type::TypeVariable(binding, _) => {
match &*binding.borrow() {
TypeBinding::Bound(binding) => binding.occurs(target_id),
Type::NamedGeneric(type_var, _, _) | Type::TypeVariable(type_var, _) => {
match &*type_var.borrow() {
TypeBinding::Bound(binding) => {
type_var.id() == target_id || binding.occurs(target_id)
}
TypeBinding::Unbound(id) => *id == target_id,
}
}
Expand Down

0 comments on commit 1286bbe

Please sign in to comment.