1
0

Add type checking for type arguments

This commit is contained in:
Jeff 2024-04-02 22:59:49 -04:00
parent 200a5d9127
commit 40783422d8
2 changed files with 9 additions and 4 deletions

View File

@ -134,8 +134,8 @@ impl AbstractNode for FunctionCall {
.map(|r#type| r#type.node.clone()) .map(|r#type| r#type.node.clone())
.zip(self.type_arguments.into_iter().map(|r#type| r#type.node)) .zip(self.type_arguments.into_iter().map(|r#type| r#type.node))
{ {
if let Type::Argument(identifier, r#type) = type_parameter { if let Type::Argument(identifier) = type_parameter {
function_context.set_type(identifier, *r#type)?; function_context.set_type(identifier, type_argument)?;
} }
} }
}; };

View File

@ -13,7 +13,7 @@ use super::{AbstractNode, Action, WithPosition};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] #[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum Type { pub enum Type {
Any, Any,
Argument(Identifier, Box<Type>), Argument(Identifier),
Boolean, Boolean,
Float, Float,
Function { Function {
@ -51,6 +51,11 @@ impl Type {
| (Type::None, Type::None) | (Type::None, Type::None)
| (Type::Range, Type::Range) | (Type::Range, Type::Range)
| (Type::String, Type::String) => return Ok(()), | (Type::String, Type::String) => return Ok(()),
(Type::Argument(left), Type::Argument(right)) => {
if left == right {
return Ok(());
}
}
(Type::ListOf(left), Type::ListOf(right)) => { (Type::ListOf(left), Type::ListOf(right)) => {
if let Ok(()) = left.node.check(&right.node) { if let Ok(()) = left.node.check(&right.node) {
return Ok(()); return Ok(());
@ -191,7 +196,7 @@ impl Display for Type {
write!(f, ") : {}", return_type.node) write!(f, ") : {}", return_type.node)
} }
Type::Structure { name, .. } => write!(f, "{name}"), Type::Structure { name, .. } => write!(f, "{name}"),
Type::Argument(identifier, _type) => write!(f, "{identifier}"), Type::Argument(identifier) => write!(f, "{identifier}"),
} }
} }
} }