From 542a19104e5a8146284f50aae9740ca2ada5ed1e Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Mon, 4 Mar 2024 08:54:52 +0100 Subject: [PATCH] Merge pull request #9918 from 9999years/debugger-locals-for-let-expressions Expose locals from `let` expressions to the debugger (cherry picked from commit acef4f17a2daab4ccdf656bdf229792db2f779e4) Change-Id: Ib3623254f67ac762f4e7230d625e9f87dff38a84 --- .../rl-next/debugger-locals-for-let-expressions.md | 9 +++++++++ src/libexpr/nixexpr.cc | 9 +++------ 2 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 doc/manual/rl-next/debugger-locals-for-let-expressions.md diff --git a/doc/manual/rl-next/debugger-locals-for-let-expressions.md b/doc/manual/rl-next/debugger-locals-for-let-expressions.md new file mode 100644 index 000000000..736208724 --- /dev/null +++ b/doc/manual/rl-next/debugger-locals-for-let-expressions.md @@ -0,0 +1,9 @@ +--- +synopsis: "`--debugger` can now access bindings from `let` expressions" +prs: 9918 +issues: 8827. +--- + +Breakpoints and errors in the bindings of a `let` expression can now access +those bindings in the debugger. Previously, only the body of `let` expressions +could access those bindings. diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index edab297f2..b34112be1 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -470,9 +470,6 @@ void ExprCall::bindVars(EvalState & es, const std::shared_ptr & void ExprLet::bindVars(EvalState & es, const std::shared_ptr & env) { - if (es.debugRepl) - es.exprEnvs.insert(std::make_pair(this, env)); - auto newEnv = std::make_shared(nullptr, env.get(), attrs->attrs.size()); Displacement displ = 0; @@ -484,6 +481,9 @@ void ExprLet::bindVars(EvalState & es, const std::shared_ptr & for (auto & i : attrs->attrs) i.second.e->bindVars(es, i.second.inherited ? env : newEnv); + if (es.debugRepl) + es.exprEnvs.insert(std::make_pair(this, newEnv)); + body->bindVars(es, newEnv); } @@ -508,9 +508,6 @@ void ExprWith::bindVars(EvalState & es, const std::shared_ptr & break; } - if (es.debugRepl) - es.exprEnvs.insert(std::make_pair(this, env)); - attrs->bindVars(es, env); auto newEnv = std::make_shared(this, env.get()); body->bindVars(es, newEnv);