mirror of
https://github.com/erg-lang/erg.git
synced 2025-10-02 21:44:34 +00:00
fix: Type::{And, Or}(Set<Type>)
This commit is contained in:
parent
82bc710827
commit
b0c31370c5
14 changed files with 661 additions and 466 deletions
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue