Update generalize.rs

This commit is contained in:
Shunsuke Shibayama 2023-05-14 10:57:28 +09:00
parent 010426d475
commit 658ed24482

View file

@ -747,18 +747,22 @@ impl<'c, 'q, 'l, L: Locational> Dereferencer<'c, 'q, 'l, L> {
self.ctx self.ctx
.check_trait_impl(&sub_t, &super_t, self.qnames, self.loc)?; .check_trait_impl(&sub_t, &super_t, self.qnames, self.loc)?;
} }
let is_subtype = self.ctx.subtype_of(&sub_t, &super_t);
let sub_t = if DEBUG_MODE {
sub_t
} else {
self.deref_tyvar(sub_t)?
};
let super_t = if DEBUG_MODE {
super_t
} else {
self.deref_tyvar(super_t)?
};
if sub_t == super_t {
Ok(sub_t)
}
// REVIEW: Even if type constraints can be satisfied, implementation may not exist // REVIEW: Even if type constraints can be satisfied, implementation may not exist
if self.ctx.subtype_of(&sub_t, &super_t) { else if is_subtype {
let sub_t = if DEBUG_MODE {
sub_t
} else {
self.deref_tyvar(sub_t)?
};
let super_t = if DEBUG_MODE {
super_t
} else {
self.deref_tyvar(super_t)?
};
match self.variance { match self.variance {
// ?T(<: Sup) --> Sup (Sup != Obj), because completion will not work if Never is selected. // ?T(<: Sup) --> Sup (Sup != Obj), because completion will not work if Never is selected.
// ?T(:> Never, <: Obj) --> Never // ?T(:> Never, <: Obj) --> Never
@ -789,16 +793,6 @@ impl<'c, 'q, 'l, L: Locational> Dereferencer<'c, 'q, 'l, L> {
} }
} }
} else { } else {
let sub_t = if DEBUG_MODE {
sub_t
} else {
self.deref_tyvar(sub_t)?
};
let super_t = if DEBUG_MODE {
super_t
} else {
self.deref_tyvar(super_t)?
};
Err(TyCheckErrors::from(TyCheckError::subtyping_error( Err(TyCheckErrors::from(TyCheckError::subtyping_error(
self.ctx.cfg.input.clone(), self.ctx.cfg.input.clone(),
line!() as usize, line!() as usize,