@@ -308,9 +308,11 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
308308 analyze ( rhs, state)
309309 }
310310 Tree :: Block ( statements, _) => {
311+ let old_namespace = state. namespace . clone ( ) ;
311312 for statement in statements {
312313 analyze ( Box :: new ( statement. clone ( ) ) , state) ?;
313314 }
315+ state. namespace = old_namespace;
314316 Ok ( ( ) )
315317 }
316318 Tree :: LValueIdentifier ( name) => analyze ( name, state) ,
@@ -395,6 +397,7 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
395397 . filter ( |( _, v) | v. declaration ( ) . eq ( & DeclarationStatus :: Initialized ) )
396398 {
397399 if false_namespace. contains_key ( initialized_variable)
400+ && state. namespace . contains_key ( initialized_variable)
398401 && false_namespace
399402 . get ( initialized_variable)
400403 . unwrap ( )
@@ -445,11 +448,11 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
445448 Ok ( ( ) )
446449 }
447450 Tree :: For ( initializer, condition, updater, expression, _) => {
451+ let old_namespace = state. namespace . clone ( ) ;
448452 let returning_state = state. return_state . clone ( ) ;
449453 if let Some ( initializer_expression) = initializer {
450454 analyze ( initializer_expression, state) ?;
451455 }
452- let old_namespace = state. namespace . clone ( ) ;
453456 analyze ( condition. clone ( ) , state) ?;
454457 if get_variable_type ( condition, state)
455458 . ok_or ( "Variable undefined!" ) ?
@@ -458,7 +461,12 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
458461 return Err ( "Condition must be a boolean" . to_string ( ) ) ;
459462 }
460463 if let Some ( updater_expression) = updater {
464+ let names = state. namespace . iter ( ) . map ( |v| v. 0 ) . len ( ) ;
461465 analyze ( updater_expression, state) ?;
466+ let additional_names = state. namespace . iter ( ) . map ( |v| v. 0 ) . len ( ) ;
467+ if names != additional_names {
468+ return Err ( "Updater Expression cannot define variables" . to_string ( ) ) ;
469+ }
462470 }
463471 state. enter_loop ( ) ;
464472 analyze ( expression, state) ?;
0 commit comments