mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 04:09:05 +00:00
fix: method resolution bug
This commit is contained in:
parent
544fee8d59
commit
1954d27a63
3 changed files with 50 additions and 2 deletions
|
@ -1361,8 +1361,9 @@ impl Context {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut checked = vec![];
|
||||
for ctx in self
|
||||
.get_nominal_super_type_ctxs(obj.ref_t())
|
||||
.get_nominal_super_type_ctxs(&obj.ref_t().lower_bounded())
|
||||
.ok_or_else(|| {
|
||||
TyCheckError::type_not_found(
|
||||
self.cfg.input.clone(),
|
||||
|
@ -1373,6 +1374,7 @@ impl Context {
|
|||
)
|
||||
})?
|
||||
{
|
||||
checked.push(&ctx.typ);
|
||||
if let Some(vi) = ctx.get_current_scope_non_param(&attr_name.name) {
|
||||
self.validate_visibility(attr_name, vi, input, namespace)?;
|
||||
return Ok(vi.clone());
|
||||
|
@ -1395,6 +1397,45 @@ impl Context {
|
|||
}
|
||||
}
|
||||
}
|
||||
if obj.ref_t() != &obj.ref_t().lower_bounded() {
|
||||
for ctx in self
|
||||
.get_nominal_super_type_ctxs(obj.ref_t())
|
||||
.ok_or_else(|| {
|
||||
TyCheckError::type_not_found(
|
||||
self.cfg.input.clone(),
|
||||
line!() as usize,
|
||||
obj.loc(),
|
||||
self.caused_by(),
|
||||
obj.ref_t(),
|
||||
)
|
||||
})?
|
||||
{
|
||||
if checked.contains(&&ctx.typ) {
|
||||
continue;
|
||||
}
|
||||
if let Some(vi) = ctx.get_current_scope_non_param(&attr_name.name) {
|
||||
self.validate_visibility(attr_name, vi, input, namespace)?;
|
||||
return Ok(vi.clone());
|
||||
}
|
||||
for methods_ctx in ctx.methods_list.iter() {
|
||||
if let Some(vi) = methods_ctx.get_current_scope_non_param(&attr_name.name) {
|
||||
self.validate_visibility(attr_name, vi, input, namespace)?;
|
||||
return Ok(vi.clone());
|
||||
}
|
||||
}
|
||||
if let Some(ctx) = self.get_same_name_context(&ctx.name) {
|
||||
match ctx.rec_get_var_info(attr_name, AccessKind::BoundAttr, input, namespace) {
|
||||
Triple::Ok(t) => {
|
||||
return Ok(t);
|
||||
}
|
||||
Triple::Err(e) => {
|
||||
return Err(e);
|
||||
}
|
||||
Triple::None => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
match self.get_attr_type_by_name(obj, attr_name, namespace) {
|
||||
Triple::Ok(method) => {
|
||||
let def_t = self
|
||||
|
@ -3013,6 +3054,7 @@ impl Context {
|
|||
/// ```erg
|
||||
/// get_nominal_super_type_ctx(Nat) == [<Nat>, <Int>, <Float>, ..., <Obj>, <Eq>, ...]
|
||||
/// get_nominal_super_type_ctx({Nat}) == [<Type>, <Obj>, <Eq>, ...]
|
||||
/// get_nominal_super_type_ctx(?T(:> Nat, <: Eq)) == == [<Eq>, ...]
|
||||
/// ```
|
||||
pub fn get_nominal_super_type_ctxs<'a>(&'a self, t: &Type) -> Option<Vec<&'a TypeContext>> {
|
||||
match t {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue