@@ -8,6 +8,7 @@ use crate::{
88 util:: int_parsing:: parse_int,
99} ;
1010
11+ #[ derive( Clone ) ]
1112pub struct AnalysisState {
1213 return_state : ReturnState ,
1314 namespace : HashMap < Name , VariableStatus > ,
@@ -44,6 +45,7 @@ enum ReturnState {
4445 NotReturing ,
4546}
4647
48+ #[ derive( Clone ) ]
4749pub 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 ) ]
7476pub 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