Fix bug add test
This commit is contained in:
parent
501eaeee87
commit
50d5176b45
@ -216,7 +216,7 @@ impl<'a> State<'a> {
|
|||||||
CaseMatch { box cond, alternatives } => match self.expression(Node::Expr(cond))? {
|
CaseMatch { box cond, alternatives } => match self.expression(Node::Expr(cond))? {
|
||||||
Node::PrimObject { name, tag, items } => {
|
Node::PrimObject { name, tag, items } => {
|
||||||
for alt in alternatives {
|
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 {
|
let mut inner_state = State {
|
||||||
values: self.values.new_scope(None),
|
values: self.values.new_scope(None),
|
||||||
symbol_table_handle: self.symbol_table_handle.clone(),
|
symbol_table_handle: self.symbol_table_handle.clone(),
|
||||||
@ -243,7 +243,11 @@ impl<'a> State<'a> {
|
|||||||
for alt in alternatives {
|
for alt in alternatives {
|
||||||
match alt.guard {
|
match alt.guard {
|
||||||
Some(ref guard_expr) if alt.tag.is_none() => {
|
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 }
|
if a { is None -> 4, is Some(x) -> x }
|
||||||
"#;
|
"#;
|
||||||
fresh_env!(source, "99");
|
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\"");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,7 @@ impl Pattern {
|
|||||||
_ => panic!("This should never happen")
|
_ => panic!("This should never happen")
|
||||||
});
|
});
|
||||||
let guard = Some(Expr::Call {
|
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()]
|
args: vec![comparison, *cond.clone()]
|
||||||
});
|
});
|
||||||
Alternative {
|
Alternative {
|
||||||
|
Loading…
Reference in New Issue
Block a user