From c263070d376d47012c57462f8d943109a34d3ae6 Mon Sep 17 00:00:00 2001 From: Rebecca Turner Date: Mon, 3 Feb 2025 15:03:53 -0800 Subject: [PATCH] Fix crash in debugger mode using `with` Fixes this crash (#592): $ nix repl --debugger Lix 2.92.0-dev-pre20241120-66f6dbd debugger Type :? for help. nix-repl> let x = 4; in __seq x (with x; (x: builtins.break x) 1) info: breakpoint reached [1] 949722 segmentation fault (core dumped) nix repl --debugger Change-Id: I13c72941dc325ff984dcce2a84c01c89b1c552af --- lix/libexpr/eval.cc | 4 ++-- .../data/regression_l592.nix | 1 + .../data/regression_l592.test | 21 +++++++++++++++++++ .../repl_characterization.cc | 1 + 4 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 tests/functional/repl_characterization/data/regression_l592.nix create mode 100644 tests/functional/repl_characterization/data/regression_l592.test diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index e2f3b8544..2e365f2b7 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -629,7 +629,7 @@ void printStaticEnvBindings(const SymbolTable & st, const StaticEnv & se) // just for the current level of Env, not the whole chain. void printWithBindings(const SymbolTable & st, const Env & env) { - if (!env.values[0]->isThunk()) { + if (env.values[0]->type() == nAttrs) { std::set bindings; for (const auto & attr : *env.values[0]->attrs) bindings.emplace(st[attr.name]); @@ -686,7 +686,7 @@ void mapStaticEnvBindings(const SymbolTable & st, const StaticEnv & se, const En if (env.up && se.up) { mapStaticEnvBindings(st, *se.up, *env.up, vm); - if (se.isWith && !env.values[0]->isThunk()) { + if (se.isWith && env.values[0]->type() == nAttrs) { // add 'with' bindings. Bindings::iterator j = env.values[0]->attrs->begin(); while (j != env.values[0]->attrs->end()) { diff --git a/tests/functional/repl_characterization/data/regression_l592.nix b/tests/functional/repl_characterization/data/regression_l592.nix new file mode 100644 index 000000000..0962725b8 --- /dev/null +++ b/tests/functional/repl_characterization/data/regression_l592.nix @@ -0,0 +1 @@ +let x = 4; in __seq x (with x; (x: builtins.break x) 1) diff --git a/tests/functional/repl_characterization/data/regression_l592.test b/tests/functional/repl_characterization/data/regression_l592.test new file mode 100644 index 000000000..b0ba331ae --- /dev/null +++ b/tests/functional/repl_characterization/data/regression_l592.test @@ -0,0 +1,21 @@ +@args --debugger + + breakpoint reached + + nix-repl> :quit + error: + … while evaluating the file '$TEST_DATA/regression_l592.nix': + + … while calling the 'seq' builtin + at $TEST_DATA/regression_l592.nix:1:15: + 1| let x = 4; in __seq x (with x; (x: builtins.break x) 1) + | ^ + 2| + + … while calling the 'break' builtin + at $TEST_DATA/regression_l592.nix:1:36: + 1| let x = 4; in __seq x (with x; (x: builtins.break x) 1) + | ^ + 2| + + error: breakpoint reached diff --git a/tests/functional/repl_characterization/repl_characterization.cc b/tests/functional/repl_characterization/repl_characterization.cc index eccaeaf8e..8fde93c4a 100644 --- a/tests/functional/repl_characterization/repl_characterization.cc +++ b/tests/functional/repl_characterization/repl_characterization.cc @@ -177,6 +177,7 @@ REPL_TEST(no_nested_debuggers); REPL_TEST(regression_9917); REPL_TEST(regression_9918); REPL_TEST(regression_l145); +REPL_TEST(regression_l592); REPL_TEST(repl_overlays); REPL_TEST(repl_overlays_compose); REPL_TEST(repl_overlays_destructure_without_dotdotdot_errors);