Skip to content
This repository has been archived by the owner on Jul 29, 2024. It is now read-only.

Commit

Permalink
Return implementations (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavrilikhin-d authored May 4, 2024
1 parent 8c5e177 commit a8d1221
Showing 1 changed file with 26 additions and 19 deletions.
45 changes: 26 additions & 19 deletions src/semantics/implements.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::{
hir::{self, Trait, Type},
hir::{self, Function, Trait, Type},
syntax::Ranged,
};

Expand All @@ -25,26 +25,33 @@ pub struct ImplementsCheck<'s, S> {
}

impl ImplementsCheck<'_, hir::Class> {
pub fn within(self, context: &mut impl Context) -> Result<(), NotImplemented> {
pub fn within(self, context: &mut impl Context) -> Result<Vec<Function>, NotImplemented> {
let mut implemented = vec![];
for supertrait in &self.tr.read().unwrap().supertraits {
self.ty.implements(supertrait.clone()).within(context)?;
implemented.extend(
self.ty
.implements(supertrait.clone())
.within(context)?
.into_iter(),
);
}

let unimplemented: Vec<_> = self
.tr
.read()
.unwrap()
.functions
.values()
.filter(|f| {
let f = f.read().unwrap();
!f.is_definition()
&& context
.find_implementation(&f, &Type::from(self.ty.clone()))
.is_none()
})
.cloned()
.collect();
let mut unimplemented = vec![];
for f in self.tr.read().unwrap().functions.values().cloned() {
if f.read().unwrap().is_definition() {
implemented.push(f);
continue;
}

if let Some(imp) =
context.find_implementation(&f.read().unwrap(), &Type::from(self.ty.clone()))
{
implemented.push(imp);
continue;
}

unimplemented.push(f);
}

if !unimplemented.is_empty() {
let source_file = self
Expand All @@ -66,6 +73,6 @@ impl ImplementsCheck<'_, hir::Class> {
});
}

Ok(())
Ok(implemented)
}
}

0 comments on commit a8d1221

Please sign in to comment.