fix: Type::{And, Or}(Set<Type>)

This commit is contained in:
Shunsuke Shibayama 2024-09-14 21:20:05 +09:00
parent 82bc710827
commit b0c31370c5
14 changed files with 661 additions and 466 deletions

View file

@ -593,35 +593,11 @@ pub fn refinement(var: Str, t: Type, pred: Predicate) -> Type {
}
pub fn and(lhs: Type, rhs: Type) -> Type {
match (lhs, rhs) {
(Type::And(l, r), other) | (other, Type::And(l, r)) => {
if l.as_ref() == &other {
and(*r, other)
} else if r.as_ref() == &other {
and(*l, other)
} else {
Type::And(Box::new(Type::And(l, r)), Box::new(other))
}
}
(Type::Obj, other) | (other, Type::Obj) => other,
(lhs, rhs) => Type::And(Box::new(lhs), Box::new(rhs)),
}
lhs & rhs
}
pub fn or(lhs: Type, rhs: Type) -> Type {
match (lhs, rhs) {
(Type::Or(l, r), other) | (other, Type::Or(l, r)) => {
if l.as_ref() == &other {
or(*r, other)
} else if r.as_ref() == &other {
or(*l, other)
} else {
Type::Or(Box::new(Type::Or(l, r)), Box::new(other))
}
}
(Type::Never, other) | (other, Type::Never) => other,
(lhs, rhs) => Type::Or(Box::new(lhs), Box::new(rhs)),
}
lhs | rhs
}
pub fn ors(tys: impl IntoIterator<Item = Type>) -> Type {