Skip to content

Commit b7ee9a4

Browse files
committed
fix(semantic): fixing more namespace issues
1 parent 8a6cedb commit b7ee9a4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/semantic/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,11 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
298298
analyze(rhs, state)
299299
}
300300
Tree::Block(statements, _) => {
301+
let old_namespace = state.namespace.clone();
301302
for statement in statements {
302303
analyze(Box::new(statement.clone()), state)?;
303304
}
305+
state.namespace = old_namespace;
304306
Ok(())
305307
}
306308
Tree::LValueIdentifier(name) => analyze(name, state),
@@ -394,6 +396,7 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
394396
Ok(())
395397
}
396398
Tree::For(initializer, condition, updater, expression, _) => {
399+
let old_namespace = state.namespace.clone();
397400
let returning_state = state.return_state.clone();
398401
if let Some(initializer_expression) = initializer {
399402
analyze(initializer_expression, state)?;
@@ -406,14 +409,13 @@ pub fn analyze(tree: Box<Tree>, state: &mut AnalysisState) -> Result<(), String>
406409
return Err("Condition must be a boolean".to_string());
407410
}
408411
if let Some(updater_expression) = updater {
409-
let old_state = state.clone();
410412
analyze(updater_expression, state)?;
411-
*state = old_state;
412413
}
413414
state.enter_loop();
414415
analyze(expression, state)?;
415416
state.return_state = returning_state;
416417
state.exit_loop();
418+
state.namespace = old_namespace;
417419
Ok(())
418420
}
419421
}

0 commit comments

Comments
 (0)