aboutsummaryrefslogtreecommitdiffstats
path: root/src/compiler.rs
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2021-03-07 16:07:36 +0100
committerGustav Sörnäs <gustav@sornas.net>2021-03-07 16:07:36 +0100
commitd96ca7b986573a98cefdb67026516fd014a93c71 (patch)
treebd9b85f633962d562bbc9c298a827e94c1fb3c2c /src/compiler.rs
parent1d8ce1dcc22a3f14b032d8be3e8a88a8cdbb538c (diff)
downloadsylt-d96ca7b986573a98cefdb67026516fd014a93c71.tar.gz
fix parameters colliding with global variables
Diffstat (limited to 'src/compiler.rs')
-rw-r--r--src/compiler.rs10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/compiler.rs b/src/compiler.rs
index 116e3d2..b5d05d6 100644
--- a/src/compiler.rs
+++ b/src/compiler.rs
@@ -1124,17 +1124,19 @@ impl Compiler {
}
fn define(&mut self, mut var: Variable) -> Result<usize, ()> {
- if let Some(var) = self.find_variable(&var.name) {
- if var.scope == self.frame().scope {
+ let frame = self.frame();
+
+ if let Some(res) = frame.find_local(&var.name).or(frame.find_upvalue(&var.name)) {
+ if res.scope == frame.scope {
error!(self, format!("Multiple definitions of '{}' in this block.",
- var.name));
+ res.name));
return Err(());
}
}
let slot = self.stack().len();
var.slot = slot;
- var.scope = self.frame().scope;
+ var.scope = frame.scope;
var.line = self.line();
self.stack_mut().push(var);
Ok(slot)