8000 [fix] Fix the type checker for IfThenElse · UnBCIC-TP2/r-python@5abb696 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5abb696

Browse files
committed
[fix] Fix the type checker for IfThenElse
1 parent e6c4d68 commit 5abb696

File tree

2 files changed

+120
-270
lines changed

2 files changed

+120
-270
lines changed

src/environment/environment.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ impl<A: Clone> Environment<A> {
9898
pub fn pop(&mut self) -> () {
9999
self.stack.pop_front();
100100
}
101+
102+
pub fn get_all_variables(&self) -> Vec<(Name, A)> {
103+
let mut vars = Vec::new();
104+
105+
// First get variables from local scopes (in reverse order to respect shadowing)
106+
for scope in self.stack.iter() {
107+
for (name, value) in &scope.variables {
108+
if !vars.iter().any(|(n, _)| n == name) {
109+
vars.push((name.clone(), value.clone()));
110+
}
111+
}
112+
}
113+
114+
// Then get variables from global scope (if not already found)
115+
for (name, value) in &self.globals.variables {
116+
if !vars.iter().any(|(n, _)| n == name) {
117+
vars.push((name.clone(), value.clone()));
118+
}
119+
}
120+
121+
vars
122+
}
101123
}
102124

103125
#[cfg(test)]

0 commit comments

Comments
 (0)
0