Fix merging child stack into parent (#12426)

# Description
Fixes #12423 where changes to mutable variables are not properly
persisted after a REPL entry.
This commit is contained in:
Ian Manske
2024-04-06 15:03:22 +00:00
committed by GitHub
parent eb36dbb091
commit 03667bdf8c
5 changed files with 33 additions and 19 deletions

View File

@ -112,7 +112,7 @@ impl Stack {
///
/// Here it is assumed that child was created with a call to Stack::with_parent
/// with parent
pub fn with_changes_from_child(parent: Arc<Stack>, mut child: Stack) -> Stack {
pub fn with_changes_from_child(parent: Arc<Stack>, child: Stack) -> Stack {
// we're going to drop the link to the parent stack on our new stack
// so that we can unwrap the Arc as a unique reference
//
@ -121,15 +121,18 @@ impl Stack {
drop(child.parent_stack);
let mut unique_stack = Stack::unwrap_unique(parent);
unique_stack.vars.append(&mut child.vars);
unique_stack
.vars
.retain(|(var, _)| !child.parent_deletions.contains(var));
for (var, value) in child.vars {
unique_stack.add_var(var, value);
}
unique_stack.env_vars = child.env_vars;
unique_stack.env_hidden = child.env_hidden;
unique_stack.active_overlays = child.active_overlays;
unique_stack
.vars
.retain(|(var, _)| !child.parent_deletions.contains(var));
unique_stack
}
pub fn with_env(
&mut self,
env_vars: &[EnvVars],