Pass enum match test
This commit is contained in:
parent
5559860699
commit
14eedc6a2a
@ -16,6 +16,9 @@ pub struct Match {
|
|||||||
matcher: Expression,
|
matcher: Expression,
|
||||||
options: Vec<(MatchPattern, Statement)>,
|
options: Vec<(MatchPattern, Statement)>,
|
||||||
fallback: Option<Box<Statement>>,
|
fallback: Option<Box<Statement>>,
|
||||||
|
|
||||||
|
#[serde(skip)]
|
||||||
|
context: Context,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AbstractTree for Match {
|
impl AbstractTree for Match {
|
||||||
@ -53,6 +56,7 @@ impl AbstractTree for Match {
|
|||||||
matcher,
|
matcher,
|
||||||
options,
|
options,
|
||||||
fallback,
|
fallback,
|
||||||
|
context: Context::default(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,9 +69,15 @@ impl AbstractTree for Match {
|
|||||||
fn validate(&self, _source: &str, _context: &Context) -> Result<(), ValidationError> {
|
fn validate(&self, _source: &str, _context: &Context) -> Result<(), ValidationError> {
|
||||||
self.matcher.validate(_source, _context)?;
|
self.matcher.validate(_source, _context)?;
|
||||||
|
|
||||||
for (expression, statement) in &self.options {
|
for (match_pattern, statement) in &self.options {
|
||||||
expression.validate(_source, _context)?;
|
if let MatchPattern::EnumPattern(enum_pattern) = match_pattern {
|
||||||
statement.validate(_source, _context)?;
|
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 {
|
if let Some(statement) = &self.fallback {
|
||||||
|
Loading…
Reference in New Issue
Block a user