Add type argument test

This commit is contained in:
Jeff 2024-03-29 15:52:02 -04:00
parent e1002b21d9
commit 200a5d9127
3 changed files with 17 additions and 5 deletions

View File

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

View File

@ -13,7 +13,7 @@ use super::{AbstractNode, Action, WithPosition};
#[derive(Clone, Debug, Eq, PartialEq, PartialOrd, Ord)]
pub enum Type {
Any,
Argument(Identifier),
Argument(Identifier, Box<Type>),
Boolean,
Float,
Function {
@ -191,7 +191,7 @@ impl Display for Type {
write!(f, ") : {}", return_type.node)
}
Type::Structure { name, .. } => write!(f, "{name}"),
Type::Argument(identifier) => write!(f, "{identifier}"),
Type::Argument(identifier, _type) => write!(f, "{identifier}"),
}
}
}

View File

@ -4,7 +4,19 @@ use dust_lang::{
*,
};
use dust_lang::interpret;
#[test]
fn function_call_with_type_argument() {
assert_eq!(
interpret(
"test",
"
foobar = (T)(x : T) T { x }
foobar::(int)::(42)
",
),
Ok(Some(Value::integer(42)))
);
}
#[test]
fn function_call() {