Skip to content

Commit 28a160d

Browse files
committed
fix(semantic): do not count definitions in for postcondition
1 parent 0d37aa9 commit 28a160d

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/semantic/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ use crate::{
88
util::int_parsing::parse_int,
99
};
1010

11+
#[derive(Clone)]
1112
pub struct AnalysisState {
1213
return_state: ReturnState,
1314
namespace: HashMap<Name, VariableStatus>,
@@ -44,6 +45,7 @@ enum ReturnState {
4445
NotReturing,
4546
}
4647

48+
#[derive(Clone)]
4749
pub struct VariableStatus {
4850
type_status: Type,
4951
declaration_status: DeclarationStatus,
@@ -70,7 +72,7 @@ impl VariableStatus {
7072
}
7173
}
7274

73-
#[derive(PartialEq, PartialOrd)]
75+
#[derive(PartialEq, PartialOrd, Clone)]
7476
pub enum DeclarationStatus {
7577
Declared,
7678
Initialized,
@@ -298,9 +300,6 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
298300
Tree::Block(statements, _) => {
299301
for statement in statements {
300302
analyze(Box::new(statement.clone()), state)?;
301-
if let Tree::Return(_, _) = statement {
302-
break;
303-
}
304303
}
305304
Ok(())
306305
}
@@ -404,7 +403,9 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
404403
return Err("Condition must be a boolean".to_string());
405404
}
406405
if let Some(updater_expression) = updater {
406+
let old_state = state.clone();
407407
analyze(updater_expression, state)?;
408+
*state = old_state;
408409
}
409410
state.enter_loop();
410411
analyze(expression, state)?;

0 commit comments

Comments
 (0)