Skip to content

Commit f8a883e

Browse files
committed
feat: implement type checking for trait impl blocks
- Add check_impl_block() method to TypeChecker - Convert TypedMethodParam to TypedParameter for type checking - Import CallingConvention and Visibility from type_registry - Type check each method in impl blocks using existing function checking logic Impl blocks (TypedTraitImpl) are now properly type checked instead of showing "declaration type not yet fully implemented" warnings.
1 parent ec474e1 commit f8a883e

1 file changed

Lines changed: 44 additions & 2 deletions

File tree

crates/typed_ast/src/type_checker.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::constraint_solver::{Constraint as SolverConstraint, ConstraintSolver}
1010
use crate::diagnostics::{codes, DiagnosticCollector};
1111
use crate::source::Span;
1212
use crate::type_inference::{InferenceContext, InferenceError};
13-
use crate::type_registry::{MethodSig, Mutability, ParamInfo, PrimitiveType, Type, TypeBound};
13+
use crate::type_registry::{CallingConvention, MethodSig, Mutability, ParamInfo, PrimitiveType, Type, TypeBound, Visibility};
1414
use crate::{typed_ast::*, AsyncKind};
1515
use std::collections::HashMap;
1616
use string_interner::Symbol as SymbolTrait;
@@ -650,10 +650,15 @@ impl TypeChecker {
650650
self.emit_type_error(err, span);
651651
}
652652
}
653+
TypedDeclaration::Impl(impl_block) => {
654+
// Type check impl block
655+
if let Err(err) = self.check_impl_block(impl_block) {
656+
self.emit_type_error(err, span);
657+
}
658+
}
653659
// TODO: Implement other declaration types
654660
TypedDeclaration::Class(_)
655661
| TypedDeclaration::Interface(_)
656-
| TypedDeclaration::Impl(_)
657662
| TypedDeclaration::Enum(_)
658663
| TypedDeclaration::TypeAlias(_)
659664
| TypedDeclaration::Module(_)
@@ -673,6 +678,43 @@ impl TypeChecker {
673678
}
674679
}
675680

681+
/// Type check an impl block
682+
fn check_impl_block(&mut self, impl_block: &TypedTraitImpl) -> Result<(), TypeError> {
683+
// Type check each method in the impl block
684+
for method in &impl_block.methods {
685+
// Convert method params to function params
686+
let params: Vec<TypedParameter> = method.params.iter().map(|p| {
687+
TypedParameter {
688+
name: p.name,
689+
ty: p.ty.clone(),
690+
mutability: p.mutability,
691+
kind: p.kind.clone(),
692+
default_value: p.default_value.clone(),
693+
attributes: p.attributes.clone(),
694+
span: p.span,
695+
}
696+
}).collect();
697+
698+
// Create a function-like structure from the method to reuse function checking
699+
let func = TypedFunction {
700+
name: method.name,
701+
type_params: vec![],
702+
params,
703+
return_type: method.return_type.clone(),
704+
body: method.body.clone(),
705+
visibility: Visibility::Public,
706+
is_async: method.is_async,
707+
is_external: false,
708+
calling_convention: CallingConvention::Default,
709+
link_name: None,
710+
};
711+
712+
self.check_function(&func)?;
713+
}
714+
715+
Ok(())
716+
}
717+
676718
/// Type check a function
677719
fn check_function(&mut self, func: &TypedFunction) -> Result<(), TypeError> {
678720
self.push_scope();

0 commit comments

Comments
 (0)