Fix bug with capturing undefined variable.

This commit is contained in:
Stephen Chung
2022-07-29 09:43:40 +08:00
parent ea38185cac
commit fc976172e7
3 changed files with 22 additions and 7 deletions

View File

@@ -1016,7 +1016,7 @@ impl Engine {
// Share statement
#[cfg(not(feature = "no_closure"))]
Stmt::Share(name, ..) => {
Stmt::Share(name, pos) => {
if let Some((index, ..)) = scope.get_index(name) {
let val = scope.get_mut_by_index(index);
@@ -1024,10 +1024,10 @@ impl Engine {
// Replace the variable with a shared value.
*val = std::mem::take(val).into_shared();
}
Ok(Dynamic::UNIT)
} else {
unreachable!("variable {} not found for sharing", name);
Err(ERR::ErrorVariableNotFound(name.to_string(), *pos).into())
}
Ok(Dynamic::UNIT)
}
_ => unreachable!("statement cannot be evaluated: {:?}", stmt),