mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 04:24:43 +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(
|
||||
|
|
|
@ -1037,7 +1037,9 @@ impl<A: ASTBuildable> GenericASTLowerer<A> {
|
|||
let res = if self.module.context.is_class(sup) {
|
||||
tmp.register_base_class(&self.module.context, sup.clone())
|
||||
} else {
|
||||
tmp.register_trait(&self.module.context, sup.clone())
|
||||
let class = tmp.typ.clone();
|
||||
let imp = self.module.context.register_trait_impl(&class, sup, ident);
|
||||
imp.and(tmp.register_trait(&self.module.context, sup.clone()))
|
||||
};
|
||||
res.map_err(|err| {
|
||||
let ctx = self.module.context.rec_get_mut_type(&name).unwrap();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue