Skip to content

Commit

Permalink
types: add type bound to occurscheck error variant
Browse files Browse the repository at this point in the history
I originally wanted to do this but couldn't because we weren't capping
the depth of error bound prints. Now we are.
  • Loading branch information
apoelstra committed Jun 25, 2024
1 parent 2bf7a61 commit 868964a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/node/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ mod tests {

assert!(matches!(
node.finalize_types_non_program(),
Err(crate::Error::Type(types::Error::OccursCheck)),
Err(crate::Error::Type(types::Error::OccursCheck { .. })),
));
}

Expand All @@ -320,7 +320,7 @@ mod tests {

assert!(matches!(
comp2.finalize_types_non_program(),
Err(crate::Error::Type(types::Error::OccursCheck)),
Err(crate::Error::Type(types::Error::OccursCheck { .. })),
));
}

Expand All @@ -347,7 +347,7 @@ mod tests {

assert!(matches!(
comp8.finalize_types_non_program(),
Err(crate::Error::Type(types::Error::OccursCheck)),
Err(crate::Error::Type(types::Error::OccursCheck { .. })),
));
}

Expand Down
12 changes: 8 additions & 4 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub enum Error {
hint: &'static str,
},
/// A type is recursive (i.e., occurs within itself), violating the "occurs check"
OccursCheck,
OccursCheck { infinite_bound: Arc<Bound> },
}

impl fmt::Display for Error {
Expand Down Expand Up @@ -131,7 +131,9 @@ impl fmt::Display for Error {
type1, type2, hint,
)
}
Error::OccursCheck => f.write_str("detected infinitely-sized type"),
Error::OccursCheck { infinite_bound } => {
write!(f, "infinitely-sized type {}", infinite_bound,)
}
}
}
}
Expand Down Expand Up @@ -471,13 +473,15 @@ impl Type {

// First, do occurs-check to ensure that we have no infinitely sized types.
let mut occurs_check = HashSet::new();
for data in bound.verbose_pre_order_iter::<NoSharing>(None) {
for data in Arc::clone(&bound).verbose_pre_order_iter::<NoSharing>(None) {
if data.is_complete {
occurs_check.remove(&(data.node.as_ref() as *const _));
} else if data.n_children_yielded == 0
&& !occurs_check.insert(data.node.as_ref() as *const _)
{
return Err(Error::OccursCheck);
return Err(Error::OccursCheck {
infinite_bound: bound,
});
}
}

Expand Down

0 comments on commit 868964a

Please sign in to comment.