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,
});
}
} 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)?;
}

View File

@ -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,
},

View File

@ -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(())
}