From 14eedc6a2a43d9147ac38f87d91d41b12d19544a Mon Sep 17 00:00:00 2001 From: Jeff Date: Sun, 18 Feb 2024 08:27:59 -0500 Subject: [PATCH] Pass enum match test --- src/abstract_tree/match.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/abstract_tree/match.rs b/src/abstract_tree/match.rs index aaf77fa..61b415d 100644 --- a/src/abstract_tree/match.rs +++ b/src/abstract_tree/match.rs @@ -16,6 +16,9 @@ pub struct Match { matcher: Expression, options: Vec<(MatchPattern, Statement)>, fallback: Option>, + + #[serde(skip)] + context: Context, } impl AbstractTree for Match { @@ -53,6 +56,7 @@ impl AbstractTree for Match { matcher, options, fallback, + context: Context::default(), }) } @@ -65,9 +69,15 @@ impl AbstractTree for Match { fn validate(&self, _source: &str, _context: &Context) -> Result<(), ValidationError> { self.matcher.validate(_source, _context)?; - for (expression, statement) in &self.options { - expression.validate(_source, _context)?; - statement.validate(_source, _context)?; + for (match_pattern, statement) in &self.options { + if let MatchPattern::EnumPattern(enum_pattern) = match_pattern { + if let Some(identifier) = enum_pattern.inner_identifier() { + self.context.set_type(identifier.clone(), Type::Any)?; + } + } + + match_pattern.validate(_source, _context)?; + statement.validate(_source, &self.context)?; } if let Some(statement) = &self.fallback {