diff --git a/crates/rue-typing/src/check.rs b/crates/rue-typing/src/check.rs index 0d9e17f..048638d 100644 --- a/crates/rue-typing/src/check.rs +++ b/crates/rue-typing/src/check.rs @@ -564,4 +564,12 @@ mod tests { let list = alloc_list(&mut db, &types, types.bytes); check_recursive(&mut db, types.any, list); } + + #[test] + fn check_any_point() { + let (mut db, types) = setup(); + let point_end = db.alloc(Type::Pair(types.int, types.nil)); + let point = db.alloc(Type::Pair(types.int, point_end)); + check_str(&mut db, types.any, point, "(and (l val) (not (l (f val))) (l (r val)) (not (l (f (r val)))) (not (l (r (r val)))) (= (r (r val)) ()))"); + } } diff --git a/crates/rue-typing/src/check/simplify_check.rs b/crates/rue-typing/src/check/simplify_check.rs index 1f92583..5d2d24b 100644 --- a/crates/rue-typing/src/check/simplify_check.rs +++ b/crates/rue-typing/src/check/simplify_check.rs @@ -22,23 +22,37 @@ pub(crate) fn simplify_check(check: Check) -> Check { let else_ = simplify_check(*else_); Check::If(Box::new(cond), Box::new(then), Box::new(else_)) } - Check::First(first) => { - let first = simplify_check(*first); - - if first == Check::None { - Check::None - } else { - Check::First(Box::new(first)) - } - } - Check::Rest(rest) => { - let rest = simplify_check(*rest); - - if rest == Check::None { - Check::None - } else { - Check::Rest(Box::new(rest)) - } - } + Check::First(first) => match simplify_check(*first) { + Check::None => Check::None, + Check::And(items) => Check::And( + items + .into_iter() + .map(|item| Check::First(Box::new(item))) + .collect(), + ), + Check::Or(items) => Check::Or( + items + .into_iter() + .map(|item| Check::First(Box::new(item))) + .collect(), + ), + first => Check::First(Box::new(first)), + }, + Check::Rest(rest) => match simplify_check(*rest) { + Check::None => Check::None, + Check::And(items) => Check::And( + items + .into_iter() + .map(|item| Check::Rest(Box::new(item))) + .collect(), + ), + Check::Or(items) => Check::Or( + items + .into_iter() + .map(|item| Check::Rest(Box::new(item))) + .collect(), + ), + rest => Check::Rest(Box::new(rest)), + }, } }