Fix bug add test

This commit is contained in:
greg 2018-10-16 04:10:28 -07:00
parent 501eaeee87
commit 50d5176b45
2 changed files with 19 additions and 3 deletions

View File

@ -216,7 +216,7 @@ impl<'a> State<'a> {
CaseMatch { box cond, alternatives } => match self.expression(Node::Expr(cond))? {
Node::PrimObject { name, tag, items } => {
for alt in alternatives {
if alt.tag.map(|t| t == tag).unwrap_or(true) { //TODO add guard check - the semantics
if alt.tag.map(|t| t == tag).unwrap_or(true) {
let mut inner_state = State {
values: self.values.new_scope(None),
symbol_table_handle: self.symbol_table_handle.clone(),
@ -243,7 +243,11 @@ impl<'a> State<'a> {
for alt in alternatives {
match alt.guard {
Some(ref guard_expr) if alt.tag.is_none() => {
return self.block(alt.item)
match self.expression(guard_expr.clone().to_node())? {
Node::Expr(Expr::Lit(::reduced_ast::Lit::Bool(true))) =>
return self.block(alt.item),
_ => continue,
}
},
_ => ()
}
@ -512,5 +516,17 @@ let a = Some(99)
if a { is None -> 4, is Some(x) -> x }
"#;
fresh_env!(source, "99");
let source = r#"
let a = 10
if a { is 10 -> "x", is 4 -> "y" }
"#;
fresh_env!(source, "\"x\"");
let source = r#"
let a = 10
if a { is 15 -> "x", is 10 -> "y" }
"#;
fresh_env!(source, "\"y\"");
}
}

View File

@ -228,7 +228,7 @@ impl Pattern {
_ => panic!("This should never happen")
});
let guard = Some(Expr::Call {
f: Box::new(Expr::Func(Func::BuiltIn(Rc::new("=".to_string())))),
f: Box::new(Expr::Func(Func::BuiltIn(Rc::new("==".to_string())))),
args: vec![comparison, *cond.clone()]
});
Alternative {