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 {