Fixed many of the broken tests

This commit is contained in:
greg 2019-09-09 01:04:46 -07:00
parent 29f4060a71
commit 65bc32b033
3 changed files with 38 additions and 13 deletions

View File

@ -92,7 +92,7 @@ fn full_if_matching() {
let source = r#"
type Option<T> = Some(T) | None
let a = None
if a { is None -> 4, is Some(x) -> x }
if a { is Option::None -> 4, is Option::Some(x) -> x }
"#;
test_in_fresh_env!(source, "4");

View File

@ -371,6 +371,7 @@ impl Pattern {
Ignored => Subpattern { tag: None, subpatterns: vec![], guard: None, bound_vars: vec![] },
Literal(lit) => lit.to_subpattern(symbol_table),
VarOrName(Meta { n: QualifiedName(vec), .. }) => {
println!("Calling VarOrName reduction with : {:?}", vec);
//TODO this name needs to be resolved from metadata with context
let name = if vec.len() == 1 {
vec[0].clone()

View File

@ -9,7 +9,6 @@ impl ScopeResolver {
ScopeResolver { }
}
pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> {
println!("Resolving scopes - nothing so far!");
for statement in ast.0.iter_mut() {
match statement.mut_node() {
Statement::Declaration(ref mut decl) => self.decl(decl),
@ -20,11 +19,22 @@ impl ScopeResolver {
}
fn decl(&mut self, decl: &mut Declaration) -> Result<(), String> {
use Declaration::*;
match decl {
Declaration::Binding { expr, .. } => self.expr(expr),
Binding { expr, .. } => self.expr(expr),
FuncDecl(_, block) => self.block(block),
_ => Ok(()),
}
}
fn block(&mut self, block: &mut Block) -> Result<(), String> {
for statement in block.iter_mut() {
match statement.mut_node() {
Statement::Declaration(ref mut decl) => self.decl(decl),
Statement::ExpressionStatement(ref mut expr) => self.expr(expr),
}?;
}
Ok(())
}
fn expr(&mut self, expr: &mut Meta<Expression>) -> Result<(), String> {
use ExpressionKind::*;
@ -56,18 +66,32 @@ impl ScopeResolver {
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)?;
}
Lambda { params, body, .. } => {
self.block(body)?;
for param in params.iter_mut() {
if let Some(ref mut expr) = param.default {
self.expr(expr)?;
}
}
_ => ()
},
IfExpression { ref mut body, ref mut discriminator } => {
match &mut **discriminator {
Discriminator::Simple(expr) | Discriminator::BinOp(expr, _) => self.expr(expr)?
};
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)?;
}
}
}
_ => ()
}
},
_ => ()
};