diff --git a/dust-lang/src/abstract_tree/assignment.rs b/dust-lang/src/abstract_tree/assignment.rs index b4e1bf0..92ac574 100644 --- a/dust-lang/src/abstract_tree/assignment.rs +++ b/dust-lang/src/abstract_tree/assignment.rs @@ -84,6 +84,18 @@ impl Evaluate for Assignment { position: function_call.position, }); } + } else if let Some(constructor) = &self.constructor { + let r#type = constructor.clone().construct(&context)?; + + r#type + .check(&statement_type) + .map_err(|conflict| ValidationError::TypeCheck { + conflict, + actual_position: self.statement.position(), + expected_position: Some(constructor.position()), + })?; + + context.set_type(self.identifier.node.clone(), r#type.clone())?; } else { context.set_type(self.identifier.node.clone(), statement_type)?; } diff --git a/dust-lang/src/abstract_tree/mod.rs b/dust-lang/src/abstract_tree/mod.rs index 91a1ce8..084fc3c 100644 --- a/dust-lang/src/abstract_tree/mod.rs +++ b/dust-lang/src/abstract_tree/mod.rs @@ -14,7 +14,7 @@ pub mod math; pub mod statement; pub mod structure_definition; pub mod r#type; -pub mod type_alias; +pub mod type_assignment; pub mod type_constructor; pub mod value_node; pub mod r#while; @@ -42,7 +42,7 @@ pub use self::{ r#while::While, statement::Statement, structure_definition::StructureDefinition, - type_alias::TypeAssignment, + type_assignment::TypeAssignment, type_constructor::{ EnumTypeConstructor, FunctionTypeConstructor, ListTypeConstructor, TypeConstructor, }, diff --git a/dust-lang/src/abstract_tree/type_alias.rs b/dust-lang/src/abstract_tree/type_assignment.rs similarity index 80% rename from dust-lang/src/abstract_tree/type_alias.rs rename to dust-lang/src/abstract_tree/type_assignment.rs index 326aef5..4ed0ddb 100644 --- a/dust-lang/src/abstract_tree/type_alias.rs +++ b/dust-lang/src/abstract_tree/type_assignment.rs @@ -24,11 +24,11 @@ impl TypeAssignment { } impl Evaluate for TypeAssignment { - fn validate( - &self, - _context: &mut Context, - _manage_memory: bool, - ) -> Result<(), ValidationError> { + fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> { + let r#type = self.constructor.clone().construct(&context)?; + + context.set_type(self.identifier.node.clone(), r#type)?; + Ok(()) }