diff --git a/src/abstract_tree/type.rs b/src/abstract_tree/type.rs index c8a68c8..88672e2 100644 --- a/src/abstract_tree/type.rs +++ b/src/abstract_tree/type.rs @@ -136,6 +136,7 @@ impl AbstractTree for Type { let type_node = node.child(0).unwrap(); let r#type = match type_node.kind() { + "identifier" => Type::Custom(Identifier::from_syntax(type_node, _source, _context)?), "[" => { let item_type_node = node.child(1).unwrap(); let item_type = Type::from_syntax(item_type_node, _source, _context)?; @@ -185,7 +186,8 @@ impl AbstractTree for Type { } _ => { return Err(SyntaxError::UnexpectedSyntaxNode { - expected: "any, bool, float, int, num, str, option, (, [ or {".to_string(), + expected: "any, bool, float, int, num, str, option, custom type, (, [ or {" + .to_string(), actual: type_node.kind().to_string(), location: type_node.start_position(), relevant_source: _source[type_node.byte_range()].to_string(), diff --git a/tests/enums.rs b/tests/enums.rs index 046c1a1..7b7b800 100644 --- a/tests/enums.rs +++ b/tests/enums.rs @@ -22,3 +22,34 @@ fn simple_enum() { ))) ); } + +#[test] +fn nested_enum() { + let result = interpret( + " + enum Fizzbuzz { + Fizz, + Buzz, + } + enum Foobar { + Foo, + Bar(Fizzbuzz), + } + + new Foobar:Bar(new Fizzbuzz:Fizz) + ", + ); + + assert_eq!( + result, + Ok(Value::Enum(EnumInstance::new( + "Foobar".to_string(), + "Bar".to_string(), + Value::Enum(EnumInstance::new( + "Fizzbuzz".to_string(), + "Fizz".to_string(), + Value::none() + )) + ))) + ); +}