Move check_ext_var to utility module

This commit is contained in:
Ayaz Hafiz 2022-08-09 08:55:21 -07:00
parent 0cc3eae2cb
commit 275391c065
No known key found for this signature in database
GPG key ID: 0E2A37416A25EF58
3 changed files with 23 additions and 19 deletions

View file

@ -0,0 +1,19 @@
use roc_types::subs::{Content, Subs, Variable};
use crate::DeriveError;
pub(crate) fn check_empty_ext_var(
subs: &Subs,
ext_var: Variable,
is_empty_ext: impl Fn(&Content) -> bool,
) -> Result<(), DeriveError> {
let ext_content = subs.get_content_without_compacting(ext_var);
if is_empty_ext(ext_content) {
Ok(())
} else {
match ext_content {
Content::FlexVar(_) => Err(DeriveError::UnboundVar),
_ => Err(DeriveError::Underivable),
}
}
}