aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorregnat <rg@regnat.ovh>2021-12-09 16:35:27 +0100
committerregnat <rg@regnat.ovh>2021-12-09 16:35:27 +0100
commit55e3a1108cb41801c92d3697620408d9d272c2d2 (patch)
tree33c7c4281c838c389f60eb735e88bfd036725fb3
parentbc57b3854e75d3f20929fd63d69a98b8237f23b2 (diff)
Properly take the last assignment in the REPL
When a variable is assigned in the REPL, make sure to remove any possible reference to the old one so that we correctly pick the new one afterwards Fix #5706
-rw-r--r--src/nix/repl.cc2
-rw-r--r--tests/repl.sh1
2 files changed, 3 insertions, 0 deletions
diff --git a/src/nix/repl.cc b/src/nix/repl.cc
index 42143871f..f453343f3 100644
--- a/src/nix/repl.cc
+++ b/src/nix/repl.cc
@@ -672,6 +672,8 @@ void NixRepl::addVarToScope(const Symbol & name, Value & v)
{
if (displ >= envSize)
throw Error("environment full; cannot add more variables");
+ if (auto oldVar = staticEnv.find(name); oldVar != staticEnv.vars.end())
+ staticEnv.vars.erase(oldVar);
staticEnv.vars.emplace_back(name, displ);
staticEnv.sort();
env->values[displ++] = &v;
diff --git a/tests/repl.sh b/tests/repl.sh
index f592822bc..995db869c 100644
--- a/tests/repl.sh
+++ b/tests/repl.sh
@@ -1,6 +1,7 @@
source common.sh
replCmds="
+simple = 1
simple = import ./simple.nix
:b simple
:log simple