diff --git a/src/abstract_tree/for.rs b/src/abstract_tree/for.rs index 2197e45..24a2ed2 100644 --- a/src/abstract_tree/for.rs +++ b/src/abstract_tree/for.rs @@ -100,12 +100,14 @@ impl AbstractTree for For { if let Value::Range(range) = expression_run { if self.is_async { range.into_par_iter().try_for_each(|integer| { + self.context.add_allowance(key)?; self.context .set_value(key.clone(), Value::Integer(integer))?; self.block.run(source, &self.context).map(|_value| ()) })?; } else { for i in range { + self.context.add_allowance(key)?; self.context.set_value(key.clone(), Value::Integer(i))?; self.block.run(source, &self.context)?; } @@ -117,6 +119,7 @@ impl AbstractTree for For { if let Value::List(list) = &expression_run { if self.is_async { list.items()?.par_iter().try_for_each(|value| { + self.context.add_allowance(key)?; self.context.set_value(key.clone(), value.clone())?; self.block.run(source, &self.context).map(|_value| ()) })?; diff --git a/src/abstract_tree/value_node.rs b/src/abstract_tree/value_node.rs index 8a31b1e..843b334 100644 --- a/src/abstract_tree/value_node.rs +++ b/src/abstract_tree/value_node.rs @@ -179,6 +179,13 @@ impl AbstractTree for ValueNode { } } ValueNode::Map(map_node) => map_node.validate(_source, context)?, + ValueNode::Enum { name, variant, expression } => { + name.validate(_source, context)?; + + if let Some(expression) = expression { + expression.validate(_source, context)?; + } + } _ => {}, } diff --git a/tests/enums.rs b/tests/enums.rs index fe2e13e..4fc46f5 100644 --- a/tests/enums.rs +++ b/tests/enums.rs @@ -56,24 +56,30 @@ fn nested_enum() { #[test] fn enum_with_argument() { + env_logger::builder().is_test(true).try_init().unwrap(); + let result = interpret( " enum FooBar { - Foo, - Bar, + Foo + Bar + } + enum FizzBuzz { + Fizz + Buzz } - Foobar::Bar(Fizzbuzz::Fizz) + FooBar::Bar(FizzBuzz::Fizz) ", ); assert_eq!( result, Ok(Value::Enum(EnumInstance::new( - Identifier::new("Foobar"), + Identifier::new("FooBar"), Identifier::new("Bar"), Some(Value::Enum(EnumInstance::new( - Identifier::new("Fizzbuzz"), + Identifier::new("FizzBuzz"), Identifier::new("Fizz"), Some(Value::none()) )))