Pass all tests

This commit is contained in:
Jeff 2024-06-19 12:12:28 -04:00
parent fecc62811d
commit e7e5d1c08d
3 changed files with 19 additions and 7 deletions

View File

@ -84,6 +84,18 @@ impl Evaluate for Assignment {
position: function_call.position, 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 { } else {
context.set_type(self.identifier.node.clone(), statement_type)?; context.set_type(self.identifier.node.clone(), statement_type)?;
} }

View File

@ -14,7 +14,7 @@ pub mod math;
pub mod statement; pub mod statement;
pub mod structure_definition; pub mod structure_definition;
pub mod r#type; pub mod r#type;
pub mod type_alias; pub mod type_assignment;
pub mod type_constructor; pub mod type_constructor;
pub mod value_node; pub mod value_node;
pub mod r#while; pub mod r#while;
@ -42,7 +42,7 @@ pub use self::{
r#while::While, r#while::While,
statement::Statement, statement::Statement,
structure_definition::StructureDefinition, structure_definition::StructureDefinition,
type_alias::TypeAssignment, type_assignment::TypeAssignment,
type_constructor::{ type_constructor::{
EnumTypeConstructor, FunctionTypeConstructor, ListTypeConstructor, TypeConstructor, EnumTypeConstructor, FunctionTypeConstructor, ListTypeConstructor, TypeConstructor,
}, },

View File

@ -24,11 +24,11 @@ impl TypeAssignment {
} }
impl Evaluate for TypeAssignment { impl Evaluate for TypeAssignment {
fn validate( fn validate(&self, context: &mut Context, _manage_memory: bool) -> Result<(), ValidationError> {
&self, let r#type = self.constructor.clone().construct(&context)?;
_context: &mut Context,
_manage_memory: bool, context.set_type(self.identifier.node.clone(), r#type)?;
) -> Result<(), ValidationError> {
Ok(()) Ok(())
} }