Type checking in switch case condition.
This commit is contained in:
parent
770b2e04cc
commit
299d6ef308
@ -13,6 +13,7 @@ Enhancements
|
|||||||
------------
|
------------
|
||||||
|
|
||||||
* `Module::eval_ast_as_new_raw` is made public as a low-level API.
|
* `Module::eval_ast_as_new_raw` is made public as a low-level API.
|
||||||
|
* Improper `switch` case condition syntax is now caught at parse time.
|
||||||
|
|
||||||
|
|
||||||
Version 1.6.1
|
Version 1.6.1
|
||||||
|
@ -122,7 +122,9 @@ impl fmt::Debug for OpAssignment<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A statements block with an optional condition.
|
/// A statements block with a condition.
|
||||||
|
///
|
||||||
|
/// The condition may simply be [`Expr::BoolConstant`] with `true` if there is actually no condition.
|
||||||
#[derive(Debug, Clone, Hash)]
|
#[derive(Debug, Clone, Hash)]
|
||||||
pub struct ConditionalStmtBlock {
|
pub struct ConditionalStmtBlock {
|
||||||
/// Condition.
|
/// Condition.
|
||||||
|
@ -1054,7 +1054,12 @@ impl Engine {
|
|||||||
Some(self.parse_expr(input, state, lib, settings.level_up())?);
|
Some(self.parse_expr(input, state, lib, settings.level_up())?);
|
||||||
|
|
||||||
let condition = if match_token(input, Token::If).0 {
|
let condition = if match_token(input, Token::If).0 {
|
||||||
self.parse_expr(input, state, lib, settings.level_up())?
|
ensure_not_statement_expr(input, "a boolean")?;
|
||||||
|
let guard = self
|
||||||
|
.parse_expr(input, state, lib, settings.level_up())?
|
||||||
|
.ensure_bool_expr()?;
|
||||||
|
ensure_not_assignment(input)?;
|
||||||
|
guard
|
||||||
} else {
|
} else {
|
||||||
Expr::BoolConstant(true, Position::NONE)
|
Expr::BoolConstant(true, Position::NONE)
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user