Merge pull request #5752 from NixOS/5706-repl-reassign

Properly take the last assignment in the REPL
This commit is contained in:
Eelco Dolstra 2021-12-09 20:16:13 +01:00 committed by GitHub
commit c7b66caaca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 0 deletions

View File

@ -672,6 +672,8 @@ void NixRepl::addVarToScope(const Symbol & name, Value & v)
{ {
if (displ >= envSize) if (displ >= envSize)
throw Error("environment full; cannot add more variables"); 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.vars.emplace_back(name, displ);
staticEnv.sort(); staticEnv.sort();
env->values[displ++] = &v; env->values[displ++] = &v;

View File

@ -1,6 +1,7 @@
source common.sh source common.sh
replCmds=" replCmds="
simple = 1
simple = import ./simple.nix simple = import ./simple.nix
:b simple :b simple
:log simple :log simple