From 4ab838509b50e0d7d13f5e08786c03dae0d12967 Mon Sep 17 00:00:00 2001 From: Jeff Date: Thu, 11 Jul 2024 18:15:03 -0400 Subject: [PATCH] Break one test with new validation --- dust-lang/src/abstract_tree/value_node.rs | 33 ++++++++++++++++++----- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/dust-lang/src/abstract_tree/value_node.rs b/dust-lang/src/abstract_tree/value_node.rs index 44d014d..8ce19e5 100644 --- a/dust-lang/src/abstract_tree/value_node.rs +++ b/dust-lang/src/abstract_tree/value_node.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::{ context::Context, error::{RuntimeError, ValidationError}, - identifier::Identifier, + identifier::{self, Identifier}, Value, }; @@ -111,12 +111,31 @@ impl AbstractNode for ValueNode { } } - if let Some(Type::Enum { variants, .. }) = context.get_type(&type_name.node)? { - if variants - .iter() - .find(|(identifier, _)| identifier == &variant.node) - .is_none() - { + if let Some(Type::Enum { name, variants, .. }) = context.get_type(&type_name.node)? { + let mut found = false; + + for (identifier, content) in &variants { + if identifier == &variant.node { + found = true; + } + + if let Some(content) = content { + for r#type in content { + if let Type::Generic { + concrete_type: None, + .. + } = r#type + { + return Err(ValidationError::FullTypeNotKnown { + identifier: name, + position: variant.position, + }); + } + } + } + } + + if !found { return Err(ValidationError::EnumVariantNotFound { identifier: variant.node.clone(), position: variant.position,