aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile2
-rw-r--r--doc/manual/rl-next/dup-attr-errors.md22
-rw-r--r--flake.nix6
-rw-r--r--src/libexpr/gc-small-vector.hh3
-rw-r--r--src/libexpr/parser-state.hh4
-rw-r--r--src/libexpr/primops.cc21
-rw-r--r--tests/functional/lang/eval-fail-dupAttr-deep.err.exp5
-rw-r--r--tests/functional/lang/eval-fail-dupAttr-deep.nix1
-rw-r--r--tests/functional/lang/eval-fail-dupAttr-inherit.err.exp5
-rw-r--r--tests/functional/lang/eval-fail-dupAttr-inherit.nix1
-rw-r--r--tests/functional/lang/eval-fail-dupAttr.err.exp5
-rw-r--r--tests/functional/lang/eval-fail-dupAttr.nix1
-rw-r--r--tests/unit/libexpr/primops.cc2
13 files changed, 55 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index 87cfc0699..557aa1cc4 100644
--- a/Makefile
+++ b/Makefile
@@ -61,7 +61,7 @@ endif
OPTIMIZE = 1
ifeq ($(OPTIMIZE), 1)
- GLOBAL_CXXFLAGS += -O3 $(CXXLTO)
+ GLOBAL_CXXFLAGS += -O2 $(CXXLTO)
GLOBAL_LDFLAGS += $(CXXLTO)
else
GLOBAL_CXXFLAGS += -O0 -U_FORTIFY_SOURCE
diff --git a/doc/manual/rl-next/dup-attr-errors.md b/doc/manual/rl-next/dup-attr-errors.md
new file mode 100644
index 000000000..127c8ceb1
--- /dev/null
+++ b/doc/manual/rl-next/dup-attr-errors.md
@@ -0,0 +1,22 @@
+---
+synopsis: Duplicate attribute reports are more accurate
+# prs: cl 557
+---
+
+Duplicate attribute errors are now more accurate, showing the path at which an error was detected rather than the full, possibly longer, path that caused the error.
+Error reports are now
+```ShellSession
+$ nix eval --expr '{ a.b = 1; a.b.c.d = 1; }'
+error: attribute 'a.b' already defined at «string»:1:3
+ at «string»:1:12:
+ 1| { a.b = 1; a.b.c.d = 1;
+ | ^
+```
+instead of
+```ShellSession
+$ nix eval --expr '{ a.b = 1; a.b.c.d = 1; }'
+error: attribute 'a.b.c.d' already defined at «string»:1:3
+ at «string»:1:12:
+ 1| { a.b = 1; a.b.c.d = 1;
+ | ^
+```
diff --git a/flake.nix b/flake.nix
index 62037e1e3..11c461896 100644
--- a/flake.nix
+++ b/flake.nix
@@ -328,9 +328,6 @@
installFlags = "sysconfdir=$(out)/etc";
strictDeps = false;
- # Required to make non-NixOS Linux not complain about missing locale files during configure in a dev shell
- ${if stdenv.isLinux then "LOCALE_ARCHIVE" else null} = "${pkgs.glibcLocales}/lib/locale/locale-archive";
-
shellHook = ''
PATH=$prefix/bin:$PATH
unset PYTHONPATH
@@ -339,6 +336,9 @@
# Make bash completion work.
XDG_DATA_DIRS+=:$out/share
'';
+ } // lib.optionalAttrs (stdenv.isLinux && pkgs.glibcLocales != null) {
+ # Required to make non-NixOS Linux not complain about missing locale files during configure in a dev shell
+ LOCALE_ARCHIVE = "${lib.getLib pkgs.glibcLocales}/lib/locale/locale-archive";
});
in
forAllSystems (system:
diff --git a/src/libexpr/gc-small-vector.hh b/src/libexpr/gc-small-vector.hh
index 7f4f08fc7..94c3ad28b 100644
--- a/src/libexpr/gc-small-vector.hh
+++ b/src/libexpr/gc-small-vector.hh
@@ -4,6 +4,7 @@
#if HAVE_BOEHMGC
+#define GC_INCLUDE_NEW
#include <gc/gc.h>
#include <gc/gc_cpp.h>
#include <gc/gc_allocator.h>
@@ -39,4 +40,4 @@ using SmallValueVector = SmallVector<Value *, nItems>;
template <size_t nItems>
using SmallTemporaryValueVector = SmallVector<Value, nItems>;
-} \ No newline at end of file
+}
diff --git a/src/libexpr/parser-state.hh b/src/libexpr/parser-state.hh
index a83d8c8b2..4a8b59f08 100644
--- a/src/libexpr/parser-state.hh
+++ b/src/libexpr/parser-state.hh
@@ -90,10 +90,10 @@ inline void ParserState::addAttr(ExprAttrs * attrs, AttrPath && attrPath, Expr *
if (j != attrs->attrs.end()) {
if (j->second.kind != ExprAttrs::AttrDef::Kind::Inherited) {
ExprAttrs * attrs2 = dynamic_cast<ExprAttrs *>(j->second.e);
- if (!attrs2) dupAttr(attrPath, pos, j->second.pos);
+ if (!attrs2) dupAttr({attrPath.begin(), i + 1}, pos, j->second.pos);
attrs = attrs2;
} else
- dupAttr(attrPath, pos, j->second.pos);
+ dupAttr({attrPath.begin(), i + 1}, pos, j->second.pos);
} else {
ExprAttrs * nested = new ExprAttrs;
attrs->attrs[i->symbol] = ExprAttrs::AttrDef(nested, pos);
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index 83eccb818..a5b539202 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -4299,25 +4299,16 @@ void EvalState::createBaseEnv()
.impureOnly = true,
});
- v.mkString(nixVersion);
+ v.mkString("2.18.3-lix");
addConstant("__nixVersion", v, {
.type = nString,
.doc = R"(
- The version of Nix.
+ Legacy version of Nix. Always returns "2.18.3-lix" on Lix.
- For example, where the command line returns the current Nix version,
-
- ```shell-session
- $ nix --version
- nix (Nix) 2.16.0
- ```
-
- the Nix language evaluator returns the same value:
-
- ```nix-repl
- nix-repl> builtins.nixVersion
- "2.16.0"
- ```
+ To determine if features exist, Nix scripts should instead use direct
+ means of feature detection, such as checking for existence of
+ builtins they want to use. Doing so allows for much better compatibility
+ across implementations.
)",
});
diff --git a/tests/functional/lang/eval-fail-dupAttr-deep.err.exp b/tests/functional/lang/eval-fail-dupAttr-deep.err.exp
new file mode 100644
index 000000000..bb79605c0
--- /dev/null
+++ b/tests/functional/lang/eval-fail-dupAttr-deep.err.exp
@@ -0,0 +1,5 @@
+error: attribute 'a.b.c' already defined at /pwd/lang/eval-fail-dupAttr-deep.nix:1:3
+ at /pwd/lang/eval-fail-dupAttr-deep.nix:1:14:
+ 1| { a.b.c = 1; a.b.c.a.a = 1; }
+ | ^
+ 2|
diff --git a/tests/functional/lang/eval-fail-dupAttr-deep.nix b/tests/functional/lang/eval-fail-dupAttr-deep.nix
new file mode 100644
index 000000000..186a7f705
--- /dev/null
+++ b/tests/functional/lang/eval-fail-dupAttr-deep.nix
@@ -0,0 +1 @@
+{ a.b.c = 1; a.b.c.a.a = 1; }
diff --git a/tests/functional/lang/eval-fail-dupAttr-inherit.err.exp b/tests/functional/lang/eval-fail-dupAttr-inherit.err.exp
new file mode 100644
index 000000000..7744b838f
--- /dev/null
+++ b/tests/functional/lang/eval-fail-dupAttr-inherit.err.exp
@@ -0,0 +1,5 @@
+error: attribute 'a' already defined at /pwd/lang/eval-fail-dupAttr-inherit.nix:1:15
+ at /pwd/lang/eval-fail-dupAttr-inherit.nix:1:19:
+ 1| { inherit ({}) a; a.b = 1; }
+ | ^
+ 2|
diff --git a/tests/functional/lang/eval-fail-dupAttr-inherit.nix b/tests/functional/lang/eval-fail-dupAttr-inherit.nix
new file mode 100644
index 000000000..cb8e4e625
--- /dev/null
+++ b/tests/functional/lang/eval-fail-dupAttr-inherit.nix
@@ -0,0 +1 @@
+{ inherit ({}) a; a.b = 1; }
diff --git a/tests/functional/lang/eval-fail-dupAttr.err.exp b/tests/functional/lang/eval-fail-dupAttr.err.exp
new file mode 100644
index 000000000..567791959
--- /dev/null
+++ b/tests/functional/lang/eval-fail-dupAttr.err.exp
@@ -0,0 +1,5 @@
+error: attribute 'a' already defined at /pwd/lang/eval-fail-dupAttr.nix:1:3
+ at /pwd/lang/eval-fail-dupAttr.nix:1:10:
+ 1| { a = 1; a.b = 1; }
+ | ^
+ 2|
diff --git a/tests/functional/lang/eval-fail-dupAttr.nix b/tests/functional/lang/eval-fail-dupAttr.nix
new file mode 100644
index 000000000..a33535e62
--- /dev/null
+++ b/tests/functional/lang/eval-fail-dupAttr.nix
@@ -0,0 +1 @@
+{ a = 1; a.b = 1; }
diff --git a/tests/unit/libexpr/primops.cc b/tests/unit/libexpr/primops.cc
index 71e838b32..bd174a6c0 100644
--- a/tests/unit/libexpr/primops.cc
+++ b/tests/unit/libexpr/primops.cc
@@ -611,7 +611,7 @@ namespace nix {
TEST_F(PrimOpTest, nixVersion) {
auto v = eval("builtins.nixVersion");
- ASSERT_THAT(v, IsStringEq(nixVersion));
+ ASSERT_THAT(v, IsStringEq("2.18.3-lix"));
}
TEST_F(PrimOpTest, currentSystem) {