Skip to content

Commit 6b1c370

Browse files
committed
feat: add trait impl support to TypedAST
- Added TypedTraitImpl struct for standalone impl blocks - Added TypedImplAssociatedType for associated type definitions in impls - Added Impl variant to TypedDeclaration enum - Updated type_checker and multi_paradigm_checker to handle Impl This enables parsing 'impl Trait for Type' blocks from ZynML stdlib. TypeRegistry already has register_trait() and register_implementation() methods, so the lowering infrastructure is ready.
1 parent 754bc1e commit 6b1c370

3 files changed

Lines changed: 28 additions & 0 deletions

File tree

crates/typed_ast/src/multi_paradigm_checker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ impl TypeChecker {
405405
TypedDeclaration::TypeAlias(_)
406406
| TypedDeclaration::Class(_)
407407
| TypedDeclaration::Interface(_)
408+
| TypedDeclaration::Impl(_)
408409
| TypedDeclaration::Enum(_)
409410
| TypedDeclaration::Module(_)
410411
| TypedDeclaration::Import(_)

crates/typed_ast/src/type_checker.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ impl TypeChecker {
653653
// TODO: Implement other declaration types
654654
TypedDeclaration::Class(_)
655655
| TypedDeclaration::Interface(_)
656+
| TypedDeclaration::Impl(_)
656657
| TypedDeclaration::Enum(_)
657658
| TypedDeclaration::TypeAlias(_)
658659
| TypedDeclaration::Module(_)

crates/typed_ast/src/typed_ast.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ pub enum TypedDeclaration {
5353
Variable(TypedVariable),
5454
Class(TypedClass),
5555
Interface(TypedInterface),
56+
Impl(TypedTraitImpl),
5657
Enum(TypedEnum),
5758
TypeAlias(TypedTypeAlias),
5859
Module(TypedModule),
@@ -1129,6 +1130,31 @@ pub struct TypedInterface {
11291130
pub span: Span,
11301131
}
11311132

1133+
/// Trait implementation block
1134+
/// Represents: impl TraitName<TypeArgs> for TypeName { ... }
1135+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1136+
pub struct TypedTraitImpl {
1137+
/// The trait being implemented (e.g., "Add" in "impl Add<T> for Vec<T>")
1138+
pub trait_name: InternedString,
1139+
/// Type arguments for the trait (e.g., <Tensor> in "impl Add<Tensor> for Tensor")
1140+
pub trait_type_args: Vec<Type>,
1141+
/// The type implementing the trait (e.g., "Tensor" in "impl Add for Tensor")
1142+
pub for_type: Type,
1143+
/// Method implementations
1144+
pub methods: Vec<TypedMethod>,
1145+
/// Associated type definitions (e.g., "type Output = Tensor")
1146+
pub associated_types: Vec<TypedImplAssociatedType>,
1147+
pub span: Span,
1148+
}
1149+
1150+
/// Associated type definition in impl block
1151+
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
1152+
pub struct TypedImplAssociatedType {
1153+
pub name: InternedString,
1154+
pub ty: Type,
1155+
pub span: Span,
1156+
}
1157+
11321158
/// Enum declaration
11331159
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
11341160
pub struct TypedEnum {

0 commit comments

Comments
 (0)