mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-04 02:39:20 +00:00
fix: subtype check bug
This commit is contained in:
parent
3be5d75d05
commit
b8fe8fb205
3 changed files with 20 additions and 9 deletions
|
@ -899,19 +899,20 @@ impl Context {
|
|||
self.supertype_of_tp(sup_p, fv.unsafe_crack(), variance)
|
||||
}
|
||||
(TyParam::Erased(t), _) => match variance {
|
||||
Variance::Contravariant => self.subtype_of(t, &self.get_tp_t(sub_p).unwrap_or(Obj)),
|
||||
Variance::Covariant => self.supertype_of(t, &self.get_tp_t(sub_p).unwrap_or(Obj)),
|
||||
Variance::Invariant => {
|
||||
Variance::Contravariant => {
|
||||
let rhs = self.get_tp_t(sub_p).unwrap_or(Obj);
|
||||
self.same_type_of(t, &rhs) || self.same_type_of(t, &rhs.derefine())
|
||||
self.subtype_of(t, &rhs)
|
||||
}
|
||||
// REVIEW: invariant type parameters check
|
||||
Variance::Covariant | Variance::Invariant => {
|
||||
let rhs = self.get_tp_t(sub_p).unwrap_or(Obj);
|
||||
self.supertype_of(t, &rhs)
|
||||
}
|
||||
},
|
||||
(_, TyParam::Erased(t)) => match variance {
|
||||
Variance::Contravariant => self.subtype_of(&self.get_tp_t(sup_p).unwrap_or(Obj), t),
|
||||
Variance::Covariant => self.supertype_of(&self.get_tp_t(sup_p).unwrap_or(Obj), t),
|
||||
Variance::Invariant => {
|
||||
let lhs = self.get_tp_t(sup_p).unwrap_or(Obj);
|
||||
self.same_type_of(&lhs, t) || self.same_type_of(&lhs.derefine(), t)
|
||||
Variance::Covariant | Variance::Invariant => {
|
||||
self.supertype_of(&self.get_tp_t(sup_p).unwrap_or(Obj), t)
|
||||
}
|
||||
},
|
||||
(TyParam::Array(sup), TyParam::Array(sub))
|
||||
|
|
|
@ -1967,7 +1967,11 @@ impl Context {
|
|||
.map_or(vec![], |ctx| vec![ctx])
|
||||
})
|
||||
.unwrap_or_default();
|
||||
let three = self.get_nominal_type_ctx(instance).map(|ty| &ty.ctx);
|
||||
let three = self
|
||||
.get_nominal_super_type_ctxs(instance)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|ctx| &ctx.ctx);
|
||||
let fallbacks = one.into_iter().chain(two).chain(three);
|
||||
for typ_ctx in fallbacks {
|
||||
// staticmethod __call__
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue