Fixed many of the broken tests
This commit is contained in:
parent
29f4060a71
commit
65bc32b033
@ -92,7 +92,7 @@ fn full_if_matching() {
|
|||||||
let source = r#"
|
let source = r#"
|
||||||
type Option<T> = Some(T) | None
|
type Option<T> = Some(T) | None
|
||||||
let a = 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");
|
test_in_fresh_env!(source, "4");
|
||||||
|
|
||||||
|
@ -371,6 +371,7 @@ impl Pattern {
|
|||||||
Ignored => Subpattern { tag: None, subpatterns: vec![], guard: None, bound_vars: vec![] },
|
Ignored => Subpattern { tag: None, subpatterns: vec![], guard: None, bound_vars: vec![] },
|
||||||
Literal(lit) => lit.to_subpattern(symbol_table),
|
Literal(lit) => lit.to_subpattern(symbol_table),
|
||||||
VarOrName(Meta { n: QualifiedName(vec), .. }) => {
|
VarOrName(Meta { n: QualifiedName(vec), .. }) => {
|
||||||
|
println!("Calling VarOrName reduction with : {:?}", vec);
|
||||||
//TODO this name needs to be resolved from metadata with context
|
//TODO this name needs to be resolved from metadata with context
|
||||||
let name = if vec.len() == 1 {
|
let name = if vec.len() == 1 {
|
||||||
vec[0].clone()
|
vec[0].clone()
|
||||||
|
@ -9,7 +9,6 @@ impl ScopeResolver {
|
|||||||
ScopeResolver { }
|
ScopeResolver { }
|
||||||
}
|
}
|
||||||
pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> {
|
pub fn resolve(&mut self, ast: &mut AST) -> Result<(), String> {
|
||||||
println!("Resolving scopes - nothing so far!");
|
|
||||||
for statement in ast.0.iter_mut() {
|
for statement in ast.0.iter_mut() {
|
||||||
match statement.mut_node() {
|
match statement.mut_node() {
|
||||||
Statement::Declaration(ref mut decl) => self.decl(decl),
|
Statement::Declaration(ref mut decl) => self.decl(decl),
|
||||||
@ -20,11 +19,22 @@ impl ScopeResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn decl(&mut self, decl: &mut Declaration) -> Result<(), String> {
|
fn decl(&mut self, decl: &mut Declaration) -> Result<(), String> {
|
||||||
|
use Declaration::*;
|
||||||
match decl {
|
match decl {
|
||||||
Declaration::Binding { expr, .. } => self.expr(expr),
|
Binding { expr, .. } => self.expr(expr),
|
||||||
|
FuncDecl(_, block) => self.block(block),
|
||||||
_ => Ok(()),
|
_ => 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> {
|
fn expr(&mut self, expr: &mut Meta<Expression>) -> Result<(), String> {
|
||||||
use ExpressionKind::*;
|
use ExpressionKind::*;
|
||||||
@ -56,7 +66,20 @@ impl ScopeResolver {
|
|||||||
self.invoc(arg)?;
|
self.invoc(arg)?;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
IfExpression { ref mut body, .. } => match &mut **body {
|
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, _, _) => {
|
IfExpressionBody::SimplePatternMatch(ref mut pat, _, _) => {
|
||||||
self.pattern(pat)?;
|
self.pattern(pat)?;
|
||||||
},
|
},
|
||||||
@ -68,6 +91,7 @@ impl ScopeResolver {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => ()
|
_ => ()
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => ()
|
_ => ()
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user