mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 18:58:30 +00:00
fix: collection bugs
This commit is contained in:
parent
80eae7654c
commit
f862a3f13a
6 changed files with 38 additions and 3 deletions
|
@ -4191,7 +4191,11 @@ impl Context {
|
|||
.unwrap_or(&Type::Obj);
|
||||
if self.related(base_def_t, assert_def_t) {
|
||||
// FIXME: Vec(_), List(Int, 2) -> Vec(2)
|
||||
let casted = poly(base.qual_name(), guard.to.typarams());
|
||||
let casted = if base.is_polymorphic() {
|
||||
poly(base.qual_name(), guard.to.typarams())
|
||||
} else {
|
||||
*guard.to.clone()
|
||||
};
|
||||
Ok(casted)
|
||||
} else {
|
||||
Err(TyCheckErrors::from(TyCheckError::invalid_type_cast_error(
|
||||
|
|
|
@ -2914,7 +2914,17 @@ impl Context {
|
|||
let err = TyCheckError::new(err.into(), self.cfg.input.clone(), self.caused_by());
|
||||
(Type::Failure, TyCheckErrors::from(err))
|
||||
})?;
|
||||
self.instantiate_typespec(&t_spec)
|
||||
match self.instantiate_typespec(&t_spec)? {
|
||||
// FIXME:
|
||||
Type::Mono(name) => match &name[..] {
|
||||
"GenericList" => Ok(unknown_len_list_t(Obj)),
|
||||
"GenericTuple" => Ok(homo_tuple_t(Obj)),
|
||||
"GenericDict" => Ok(dict! { Obj => Obj }.into()),
|
||||
"GenericSet" => Ok(unknown_len_set_t(Obj)),
|
||||
_ => Ok(mono(name)),
|
||||
},
|
||||
other => Ok(other),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn expr_to_value(&self, expr: ast::Expr) -> Failable<ValueObj> {
|
||||
|
|
|
@ -1508,7 +1508,12 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
|
|||
return Ok(());
|
||||
}
|
||||
let sub = mem::take(&mut sub);
|
||||
let new_sup = self.ctx.intersection(&sup, maybe_sup);
|
||||
// min(L, R) != L and R
|
||||
let new_sup = if let Some(new_sup) = self.ctx.min(&sup, maybe_sup).either() {
|
||||
new_sup.clone()
|
||||
} else {
|
||||
self.ctx.intersection(&sup, maybe_sup)
|
||||
};
|
||||
self.sub_unify(&sub, &new_sup)?;
|
||||
// ?T(:> Int, <: Int) ==> ?T == Int
|
||||
// ?T(:> List(Int, 3), <: List(?T, ?N)) ==> ?T == List(Int, 3)
|
||||
|
|
|
@ -91,10 +91,18 @@ pub fn tuple_t(args: Vec<Type>) -> Type {
|
|||
)
|
||||
}
|
||||
|
||||
pub fn homo_tuple_t(t: Type) -> Type {
|
||||
poly("HomogenousTuple", vec![TyParam::t(t)])
|
||||
}
|
||||
|
||||
pub fn set_t(elem_t: Type, len: TyParam) -> Type {
|
||||
poly("Set", vec![TyParam::t(elem_t), len])
|
||||
}
|
||||
|
||||
pub fn unknown_len_set_t(elem_t: Type) -> Type {
|
||||
set_t(elem_t, TyParam::erased(Type::Nat))
|
||||
}
|
||||
|
||||
pub fn set_mut(elem_t: Type, len: TyParam) -> Type {
|
||||
poly("Set!", vec![TyParam::t(elem_t), len])
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue