From 200a5d9127046439670ec19a35628b39303814da Mon Sep 17 00:00:00 2001 From: Jeff Date: Fri, 29 Mar 2024 15:52:02 -0400 Subject: [PATCH] Add type argument test --- dust-lang/src/abstract_tree/function_call.rs | 4 ++-- dust-lang/src/abstract_tree/type.rs | 4 ++-- dust-lang/tests/functions.rs | 14 +++++++++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/dust-lang/src/abstract_tree/function_call.rs b/dust-lang/src/abstract_tree/function_call.rs index 45b2fa2..cf08120 100644 --- a/dust-lang/src/abstract_tree/function_call.rs +++ b/dust-lang/src/abstract_tree/function_call.rs @@ -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)?; } } }; diff --git a/dust-lang/src/abstract_tree/type.rs b/dust-lang/src/abstract_tree/type.rs index fb60a3c..f779ffa 100644 --- a/dust-lang/src/abstract_tree/type.rs +++ b/dust-lang/src/abstract_tree/type.rs @@ -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), 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}"), } } } diff --git a/dust-lang/tests/functions.rs b/dust-lang/tests/functions.rs index 1daacf6..23586fd 100644 --- a/dust-lang/tests/functions.rs +++ b/dust-lang/tests/functions.rs @@ -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() {