mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-30 04:44:44 +00:00
fix: trait impl check for declared classes
This commit is contained in:
parent
22c2016eae
commit
44b4b8d82a
4 changed files with 24 additions and 6 deletions
|
@ -1129,15 +1129,23 @@ impl Context {
|
|||
}
|
||||
|
||||
pub(crate) fn register_methods(&mut self, t: &Type, ctx: &Self) {
|
||||
let declared_in = NormalizedPathBuf::from(self.module_path());
|
||||
let declared_in = declared_in.exists().then_some(declared_in);
|
||||
for impl_trait in ctx.super_traits.iter() {
|
||||
let declared_in = NormalizedPathBuf::from(self.module_path());
|
||||
let declared_in = declared_in.exists().then_some(declared_in);
|
||||
if let Some(mut impls) = self.trait_impls().get_mut(&impl_trait.qual_name()) {
|
||||
impls.insert(TraitImpl::new(t.clone(), impl_trait.clone(), declared_in));
|
||||
impls.insert(TraitImpl::new(
|
||||
t.clone(),
|
||||
impl_trait.clone(),
|
||||
declared_in.clone(),
|
||||
));
|
||||
} else {
|
||||
self.trait_impls().register(
|
||||
impl_trait.qual_name(),
|
||||
set![TraitImpl::new(t.clone(), impl_trait.clone(), declared_in)],
|
||||
set![TraitImpl::new(
|
||||
t.clone(),
|
||||
impl_trait.clone(),
|
||||
declared_in.clone()
|
||||
)],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1031,7 +1031,7 @@ impl Context {
|
|||
}
|
||||
}
|
||||
|
||||
fn register_trait_impl(
|
||||
pub(crate) fn register_trait_impl(
|
||||
&mut self,
|
||||
class: &Type,
|
||||
trait_: &Type,
|
||||
|
@ -1525,6 +1525,7 @@ impl Context {
|
|||
}
|
||||
|
||||
/// Register that a class implements a trait and its super-traits.
|
||||
/// This does not register the class-trait relationship to `shared.trait_impls` (use `register_trait_impl`).
|
||||
pub(crate) fn register_trait(&mut self, ctx: &Self, trait_: Type) -> CompileResult<()> {
|
||||
let trait_ctx = ctx.get_nominal_type_ctx(&trait_).ok_or_else(|| {
|
||||
CompileError::type_not_found(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue