Skip to content

Commit

Permalink
Check any point
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigidity committed Jul 23, 2024
1 parent 2336abe commit 665852f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 18 deletions.
8 changes: 8 additions & 0 deletions crates/rue-typing/src/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)) ()))");
}
}
50 changes: 32 additions & 18 deletions crates/rue-typing/src/check/simplify_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
}
}

0 comments on commit 665852f

Please sign in to comment.