mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +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)
|
self.supertype_of_tp(sup_p, fv.unsafe_crack(), variance)
|
||||||
}
|
}
|
||||||
(TyParam::Erased(t), _) => match variance {
|
(TyParam::Erased(t), _) => match variance {
|
||||||
Variance::Contravariant => self.subtype_of(t, &self.get_tp_t(sub_p).unwrap_or(Obj)),
|
Variance::Contravariant => {
|
||||||
Variance::Covariant => self.supertype_of(t, &self.get_tp_t(sub_p).unwrap_or(Obj)),
|
|
||||||
Variance::Invariant => {
|
|
||||||
let rhs = self.get_tp_t(sub_p).unwrap_or(Obj);
|
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 {
|
(_, TyParam::Erased(t)) => match variance {
|
||||||
Variance::Contravariant => self.subtype_of(&self.get_tp_t(sup_p).unwrap_or(Obj), t),
|
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::Covariant | Variance::Invariant => {
|
||||||
Variance::Invariant => {
|
self.supertype_of(&self.get_tp_t(sup_p).unwrap_or(Obj), t)
|
||||||
let lhs = self.get_tp_t(sup_p).unwrap_or(Obj);
|
|
||||||
self.same_type_of(&lhs, t) || self.same_type_of(&lhs.derefine(), t)
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
(TyParam::Array(sup), TyParam::Array(sub))
|
(TyParam::Array(sup), TyParam::Array(sub))
|
||||||
|
|
|
@ -1967,7 +1967,11 @@ impl Context {
|
||||||
.map_or(vec![], |ctx| vec![ctx])
|
.map_or(vec![], |ctx| vec![ctx])
|
||||||
})
|
})
|
||||||
.unwrap_or_default();
|
.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);
|
let fallbacks = one.into_iter().chain(two).chain(three);
|
||||||
for typ_ctx in fallbacks {
|
for typ_ctx in fallbacks {
|
||||||
// staticmethod __call__
|
// staticmethod __call__
|
||||||
|
|
|
@ -45,5 +45,11 @@
|
||||||
) => NoneType
|
) => NoneType
|
||||||
# TODO: S bound
|
# TODO: S bound
|
||||||
item: |T|(self: Ref .Tensor!(T, _)) -> T
|
item: |T|(self: Ref .Tensor!(T, _)) -> T
|
||||||
|
to: (|T, S: [Nat; _]|(
|
||||||
|
self: .Tensor!(T, S),
|
||||||
|
other: .DType or .Device,
|
||||||
|
non_blocking := Bool,
|
||||||
|
copy := Bool,
|
||||||
|
) -> .Tensor!(T, S))
|
||||||
|
|
||||||
.relu: |T, S: [Nat; _]|(x: .Tensor!(T, S)) -> .Tensor!(T, S)
|
.relu: |T, S: [Nat; _]|(x: .Tensor!(T, S)) -> .Tensor!(T, S)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue