1
0

Fix type error

This commit is contained in:
Jeff 2024-06-18 19:00:15 -04:00
parent d5df74363a
commit c0791ebb83

View File

@ -48,37 +48,35 @@ impl TypeConstructor {
} }
pub fn construct(self, context: &Context) -> Result<Type, ValidationError> { pub fn construct(self, context: &Context) -> Result<Type, ValidationError> {
match self { let r#type = match self {
TypeConstructor::Function(_) => todo!(), TypeConstructor::Function(_) => todo!(),
TypeConstructor::Identifier(WithPosition { TypeConstructor::Identifier(WithPosition {
node: identifier, node: identifier, ..
position,
}) => { }) => {
if let Some(r#type) = context.get_type(&identifier)? { if let Some(r#type) = context.get_type(&identifier)? {
Ok(r#type) Type::Generic(Some(Box::new(r#type)))
} else { } else {
Err(ValidationError::VariableNotFound { Type::Generic(None)
identifier,
position,
})
} }
} }
TypeConstructor::List(positioned_constructor) => { TypeConstructor::List(positioned_constructor) => {
let ListTypeConstructor { length, item_type } = positioned_constructor.node; let ListTypeConstructor { length, item_type } = positioned_constructor.node;
let constructed_type = item_type.construct(context)?; let constructed_type = item_type.construct(context)?;
Ok(Type::List { Type::List {
length, length,
item_type: Box::new(constructed_type), item_type: Box::new(constructed_type),
}) }
} }
TypeConstructor::ListOf(item_type) => { TypeConstructor::ListOf(item_type) => {
let item_type = item_type.node.construct(&context)?; let item_type = item_type.node.construct(&context)?;
Ok(Type::ListOf(Box::new(item_type))) Type::ListOf(Box::new(item_type))
}
TypeConstructor::Type(r#type) => Ok(r#type.node),
} }
TypeConstructor::Type(r#type) => r#type.node,
};
Ok(r#type)
} }
} }