diff --git a/schala-lang/language/src/schala.rs b/schala-lang/language/src/schala.rs index a3f41cd..c400a69 100644 --- a/schala-lang/language/src/schala.rs +++ b/schala-lang/language/src/schala.rs @@ -144,7 +144,7 @@ fn symbol_table(input: ast::AST, handle: &mut Schala, comp: Option<&mut PassDebu Ok(input) } -fn scope_resolution(mut input: ast::AST, handle: &mut Schala, com: Option<&mut PassDebugArtifact>) -> Result { +fn scope_resolution(mut input: ast::AST, _handle: &mut Schala, _com: Option<&mut PassDebugArtifact>) -> Result { let mut resolver = crate::scope_resolution::ScopeResolver::new(); let () = resolver.resolve(&mut input)?; Ok(input) diff --git a/schala-lang/language/src/scope_resolution.rs b/schala-lang/language/src/scope_resolution.rs index c9abeaf..da046e4 100644 --- a/schala-lang/language/src/scope_resolution.rs +++ b/schala-lang/language/src/scope_resolution.rs @@ -55,7 +55,20 @@ impl ScopeResolver { for arg in arguments.iter_mut() { self.invoc(arg)?; } - } + }, + IfExpression { ref mut body, .. } => match &mut **body { + IfExpressionBody::SimplePatternMatch(ref mut pat, _, _) => { + self.pattern(pat)?; + }, + IfExpressionBody::GuardList(guardarms) => { + for arm in guardarms.iter_mut() { + if let Guard::Pat(ref mut pat) = arm.guard { + self.pattern(pat)?; + } + } + } + _ => () + }, _ => () }; Ok(()) @@ -69,6 +82,41 @@ impl ScopeResolver { _ => Ok(()) } } + + fn pattern(&mut self, pat: &mut Pattern) -> Result<(), String> { + use Pattern::*; + match pat { + Ignored => (), + TuplePattern(patterns) => { + for pat in patterns { + self.pattern(pat)?; + } + }, + Literal(_) => (), + TupleStruct(name, patterns) => { + self.qualified_name(name); + for pat in patterns { + self.pattern(pat)?; + } + }, + Record(name, key_patterns) => { + self.qualified_name(name); + for (_, pat) in key_patterns { + self.pattern(pat)?; + } + }, + VarOrName(name) => { + self.qualified_name(name); + }, + }; + Ok(()) + } + + fn qualified_name(&mut self, meta_qualified_name: &mut Meta, ) { + let inner_name = meta_qualified_name.node(); + let fqsn = lookup_name_in_scope(inner_name); + meta_qualified_name.fqsn = Some(fqsn); + } } //TODO this is incomplete