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

@ -337,12 +337,6 @@ impl PluginTest {
// All equal, and same length
Ok(true)
}
(Value::Range { val: a_rng, .. }, Value::Range { val: b_rng, .. }) => {
Ok(a_rng.inclusion == b_rng.inclusion
&& self.value_eq(&a_rng.from, &b_rng.from)?
&& self.value_eq(&a_rng.to, &b_rng.to)?
&& self.value_eq(&a_rng.incr, &b_rng.incr)?)
}
// Must collect lazy records to compare.
(Value::LazyRecord { val: a_val, .. }, _) => self.value_eq(&a_val.collect()?, b),
(_, Value::LazyRecord { val: b_val, .. }) => self.value_eq(a, &b_val.collect()?),

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],