Double Melo causes variable deletion

This commit is contained in:
Erin 2022-04-22 21:14:53 +02:00 committed by ondra05
parent b52d07f13b
commit e19c701f3c

View file

@ -276,9 +276,16 @@ impl ExecEnv {
Stmt::HopBack => {
return Ok(HaltStatus::Hopback(stmt.span.clone()));
}
Stmt::Melo(ident) => {
*self.get_var_mut(ident)? = Variable::Melo;
}
Stmt::Melo(ident) => match self.get_var_mut(ident)? {
var @ Variable::Ref(_) => *var = Variable::Melo,
Variable::Melo => {
for s in &mut self.stack {
if s.variables.remove(&ident.item).is_some() {
break;
}
}
}
},
Stmt::Rlyeh => {
// Maybe print a creepy error message or something
// here at some point. ~~Alex
@ -366,7 +373,8 @@ impl ExecEnv {
.iter()
.map(|arg| {
if let Expr::Variable(name) = &arg.item {
self.get_var_rc_mut(&Spanned::new(name.to_owned(), arg.span.clone())).cloned()
self.get_var_rc_mut(&Spanned::new(name.to_owned(), arg.span.clone()))
.cloned()
} else {
self.eval_expr(arg).map(ValueRef::new)
}
@ -536,8 +544,7 @@ impl ExecEnv {
}
}
/// Get a mutable reference to a variable. Throw an error if the
/// variable is inaccessible or banned.
/// Get a mutable reference to a variable.
fn get_var_mut(&mut self, name: &Spanned<String>) -> Result<&mut Variable, Error> {
// This function has a lot of duplicated code with `get_var`,
// which I feel like is a bad sign...