Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix occurs check #5535

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
/// 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 @@ -1799,7 +1801,7 @@
}

let recur_on_binding = |id, replacement: &Type| {
// Prevent recuring forever if there's a `T := T` binding

Check warning on line 1804 in compiler/noirc_frontend/src/hir_def/types.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (recuring)
if replacement.type_variable_id() == Some(id) {
replacement.clone()
} else {
Expand Down Expand Up @@ -1870,7 +1872,7 @@
Type::Tuple(fields)
}
Type::Forall(typevars, typ) => {
// Trying to substitute_helper a variable de, substitute_bound_typevarsfined within a nested Forall

Check warning on line 1875 in compiler/noirc_frontend/src/hir_def/types.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (typevarsfined)
// is usually impossible and indicative of an error in the type checker somewhere.
for var in typevars {
assert!(!type_bindings.contains_key(&var.id()));
Expand Down Expand Up @@ -1924,9 +1926,11 @@
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 Expand Up @@ -2014,7 +2018,7 @@

/// Replace any `Type::NamedGeneric` in this type with a `Type::TypeVariable`
/// using to the same inner `TypeVariable`. This is used during monomorphization
/// to bind to named generics since they are unbindable during type checking.

Check warning on line 2021 in compiler/noirc_frontend/src/hir_def/types.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (unbindable)
pub fn replace_named_generics_with_type_variables(&mut self) {
match self {
Type::FieldElement
Expand Down
Loading