aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libexpr/print.cc14
-rw-r--r--tests/functional/repl_characterization/data/idempotent.test13
-rw-r--r--tests/functional/repl_characterization/repl_characterization.cc1
3 files changed, 26 insertions, 2 deletions
diff --git a/src/libexpr/print.cc b/src/libexpr/print.cc
index 87db004b2..6eb321c43 100644
--- a/src/libexpr/print.cc
+++ b/src/libexpr/print.cc
@@ -264,10 +264,15 @@ private:
return true;
}
+ if (options.force) {
+ // The item is going to be forced during printing anyway, but we need its type now.
+ state.forceValue(*item, item->determinePos(noPos));
+ }
+
// Pretty-print single-item attrsets only if they contain nested
// structures.
auto itemType = item->type();
- return itemType == nList || itemType == nAttrs || itemType == nThunk;
+ return itemType == nList || itemType == nAttrs;
}
void printAttrs(Value & v, size_t depth)
@@ -335,10 +340,15 @@ private:
return true;
}
+ if (options.force) {
+ // The item is going to be forced during printing anyway, but we need its type now.
+ state.forceValue(*item, item->determinePos(noPos));
+ }
+
// Pretty-print single-item lists only if they contain nested
// structures.
auto itemType = item->type();
- return itemType == nList || itemType == nAttrs || itemType == nThunk;
+ return itemType == nList || itemType == nAttrs;
}
void printList(Value & v, size_t depth)
diff --git a/tests/functional/repl_characterization/data/idempotent.test b/tests/functional/repl_characterization/data/idempotent.test
new file mode 100644
index 000000000..4ab087d45
--- /dev/null
+++ b/tests/functional/repl_characterization/data/idempotent.test
@@ -0,0 +1,13 @@
+A previously unforced thunk in an attribute set does not lead to indentation when it won't evaluate to a nested structure:
+ nix-repl> :p let x = 1 + 2; in [ { inherit x; } { inherit x; } ]
+ [
+ { x = 3; }
+ { x = 3; }
+ ]
+
+Same for a list:
+ nix-repl> :p let x = 1 + 2; in [ [ x ] [ x ] ]
+ [
+ [ 3 ]
+ [ 3 ]
+ ]
diff --git a/tests/functional/repl_characterization/repl_characterization.cc b/tests/functional/repl_characterization/repl_characterization.cc
index c91d6c1e3..f2cf0ca3d 100644
--- a/tests/functional/repl_characterization/repl_characterization.cc
+++ b/tests/functional/repl_characterization/repl_characterization.cc
@@ -185,5 +185,6 @@ REPL_TEST(repl_overlays_error);
REPL_TEST(repl_printing);
REPL_TEST(stack_vars);
REPL_TEST(errors);
+REPL_TEST(idempotent);
}; // namespace nix