From 3cf3fce72d3fa86144ad7dd02f116548009b92f7 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 10 Oct 2019 18:33:34 -0700 Subject: [PATCH] Fixed some code in scope resolver --- schala-lang/language/src/scope_resolution.rs | 37 +++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index 8e912f0..443ccff 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -112,7 +112,14 @@ impl<'a> ScopeResolver<'a> { self.invoc(arg)?; } }, - Lambda { params, body, .. } => { + IfExpression { discriminator, body } => { + match discriminator { + None => (), + Some(ref expr) => self.expr(expr)? + }; + self.if_expr_body(body)?; + }, + Lambda { params, body, .. } => { self.block(&body)?; for param in params.iter() { if let Some(ref expr) = param.default { @@ -134,6 +141,34 @@ impl<'a> ScopeResolver<'a> { } } + fn if_expr_body(&mut self, body: &IfExpressionBody) -> Result<(), String> { + use IfExpressionBody::*; + match body { + SimpleConditional { then_case, else_case } => { + self.block(then_case)?; + if let Some(block) = else_case { + self.block(block)?; + } + }, + SimplePatternMatch { pattern, then_case, else_case } => { + self.pattern(pattern)?; + self.block(then_case)?; + if let Some(block) = else_case { + self.block(block)?; + } + }, + CondList(conditions) => { + for arm in conditions.iter() { + if let Condition::Pattern(ref pat) = arm.condition { + self.pattern(pat)?; + } + self.block(&arm.body)?; + } + }, + } + Ok(()) + } + fn pattern(&mut self, pat: &Pattern) -> Result<(), String> { use Pattern::*; match pat {