chore: change logical operations order

This commit is contained in:
Shunsuke Shibayama 2024-09-02 19:38:41 +09:00
parent 57559b6b9f
commit 7cd895a30e
5 changed files with 12 additions and 13 deletions

View file

@ -894,8 +894,7 @@ impl Context {
let r_fields = self.fields(r);
for (l_field, l_ty) in self.fields(l) {
if let Some((r_field, r_ty)) = r_fields.get_key_value(&l_field) {
let compatible = self.supertype_of(&l_ty, r_ty);
if r_field.vis != l_field.vis || !compatible {
if r_field.vis != l_field.vis || !self.supertype_of(&l_ty, r_ty) {
return false;
}
} else {
@ -2211,9 +2210,9 @@ impl Context {
args: args2,
},
) => {
self.supertype_of_tp(receiver, sub_receiver, Variance::Covariant)
&& name == name2
name == name2
&& args.len() == args2.len()
&& self.supertype_of_tp(receiver, sub_receiver, Variance::Covariant)
&& args
.iter()
.zip(args2.iter())

View file

@ -172,9 +172,9 @@ impl<'c> Substituter<'c> {
// Or, And are commutative, choose fitting order
if qt.qual_name() == st.qual_name() && (st.qual_name() == "Or" || st.qual_name() == "And") {
// REVIEW: correct condition?
if ctx.covariant_supertype_of_tp(&qtps[0], &stps[1])
if qt != st
&& ctx.covariant_supertype_of_tp(&qtps[0], &stps[1])
&& ctx.covariant_supertype_of_tp(&qtps[1], &stps[0])
&& qt != st
{
stps.swap(0, 1);
}
@ -2608,7 +2608,7 @@ impl Context {
// FIXME: GenericDict
TyParam::FreeVar(fv)
if fv.get_type().is_some_and(|t| {
self.subtype_of(&t, &Type::Type) || &t.qual_name() == "GenericDict"
&t.qual_name() == "GenericDict" || self.subtype_of(&t, &Type::Type)
}) =>
{
// FIXME: This procedure is clearly erroneous because it breaks the type variable linkage.

View file

@ -188,14 +188,14 @@ impl Generalizer {
res.generalize();
res
} else if sup != Obj
&& !self.qnames.contains(&fv.unbound_name().unwrap())
&& self.variance == Contravariant
&& !self.qnames.contains(&fv.unbound_name().unwrap())
{
// |T <: Bool| T -> Int ==> Bool -> Int
self.generalize_t(sup, uninit)
} else if sub != Never
&& !self.qnames.contains(&fv.unbound_name().unwrap())
&& self.variance == Covariant
&& !self.qnames.contains(&fv.unbound_name().unwrap())
{
// |T :> Int| X -> T ==> X -> Int
self.generalize_t(sub, uninit)

View file

@ -2626,7 +2626,7 @@ impl Context {
);
log!(info "Substituted:\ninstance: {instance}");
debug_assert!(
self.subtype_of(&instance, &Type::Type) || instance.has_no_qvar(),
instance.has_no_qvar() || self.subtype_of(&instance, &Type::Type),
"{instance} has qvar (obj: {obj}, attr: {}",
fmt_option!(attr_name)
);
@ -4072,7 +4072,7 @@ impl Context {
pub(crate) fn recover_typarams(&self, base: &Type, guard: &GuardType) -> TyCheckResult<Type> {
let intersec = self.intersection(&guard.to, base);
let is_never =
self.subtype_of(&intersec, &Type::Never) && guard.to.as_ref() != &Type::Never;
guard.to.as_ref() != &Type::Never && self.subtype_of(&intersec, &Type::Never);
if !is_never {
return Ok(intersec);
}

View file

@ -1196,9 +1196,9 @@ impl<'c, 'l, 'u, L: Locational> Unifier<'c, 'l, 'u, L> {
// NG: (Int <: ?U); (?T <: Int)
(Or(l1, r1), Or(l2, r2)) | (And(l1, r1), And(l2, r2)) => {
if self.ctx.subtype_of(l1, l2) && self.ctx.subtype_of(r1, r2) {
let (l_sup, r_sup) = if self.ctx.subtype_of(l1, r2)
&& !l1.is_unbound_var()
let (l_sup, r_sup) = if !l1.is_unbound_var()
&& !r2.is_unbound_var()
&& self.ctx.subtype_of(l1, r2)
{
(r2, l2)
} else {