Disallow statement expressions in if and while guards to reduce code confusion.

This commit is contained in:
Stephen Chung
2020-03-20 19:50:58 +08:00
parent ed996e71d6
commit 1d98f65342
4 changed files with 55 additions and 34 deletions

View File

@@ -1159,7 +1159,7 @@ impl Engine<'_> {
Stmt::IfElse(guard, if_body, else_body) => self
.eval_expr(scope, guard)?
.downcast::<bool>()
.map_err(|_| EvalAltResult::ErrorIfGuard(guard.position()))
.map_err(|_| EvalAltResult::ErrorLogicGuard(guard.position()))
.and_then(|guard_val| {
if *guard_val {
self.eval_stmt(scope, if_body)
@@ -1186,7 +1186,7 @@ impl Engine<'_> {
return Ok(().into_dynamic());
}
}
Err(_) => return Err(EvalAltResult::ErrorIfGuard(guard.position())),
Err(_) => return Err(EvalAltResult::ErrorLogicGuard(guard.position())),
}
},