mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 12:51:10 +00:00
Add IntersectionTypeObj
This commit is contained in:
parent
9b319379d1
commit
d5b05c8a28
3 changed files with 49 additions and 2 deletions
|
@ -642,6 +642,15 @@ impl Context {
|
|||
line!(),
|
||||
))),
|
||||
},
|
||||
And => match (lhs, rhs) {
|
||||
(ValueObj::Bool(l), ValueObj::Bool(r)) => Ok(ValueObj::Bool(l && r)),
|
||||
(ValueObj::Type(lhs), ValueObj::Type(rhs)) => Ok(self.eval_and_type(lhs, rhs)),
|
||||
_ => Err(EvalErrors::from(EvalError::unreachable(
|
||||
self.cfg.input.clone(),
|
||||
fn_name!(),
|
||||
line!(),
|
||||
))),
|
||||
},
|
||||
_other => Err(EvalErrors::from(EvalError::unreachable(
|
||||
self.cfg.input.clone(),
|
||||
fn_name!(),
|
||||
|
@ -661,6 +670,19 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
fn eval_and_type(&self, lhs: TypeObj, rhs: TypeObj) -> ValueObj {
|
||||
match (lhs, rhs) {
|
||||
(TypeObj::Builtin(l), TypeObj::Builtin(r)) => {
|
||||
ValueObj::builtin_t(self.intersection(&l, &r))
|
||||
}
|
||||
(lhs, rhs) => ValueObj::gen_t(GenTypeObj::intersection(
|
||||
self.intersection(lhs.typ(), rhs.typ()),
|
||||
lhs,
|
||||
rhs,
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn eval_bin_tp(
|
||||
&self,
|
||||
op: OpKind,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue