diff --git a/lix/legacy/nix-instantiate.cc b/lix/legacy/nix-instantiate.cc index 74db1c76b..7ba3e0d51 100644 --- a/lix/legacy/nix-instantiate.cc +++ b/lix/legacy/nix-instantiate.cc @@ -51,7 +51,7 @@ void processExpr(EvalState & state, const Strings & attrPaths, if (output == okXML) printValueAsXML(state, strict, location, vRes, std::cout, context, noPos); else if (output == okJSON) { - printValueAsJSON(state, strict, vRes, v.determinePos(noPos), std::cout, context); + printValueAsJSON(state, strict, vRes, noPos, std::cout, context); std::cout << std::endl; } else { if (strict) state.forceValueDeep(vRes); diff --git a/lix/libexpr/value-to-json.cc b/lix/libexpr/value-to-json.cc index 27b6aecb6..60efd13bb 100644 --- a/lix/libexpr/value-to-json.cc +++ b/lix/libexpr/value-to-json.cc @@ -102,7 +102,7 @@ JSON printValueAsJSON(EvalState & state, bool strict, "cannot convert %1% to JSON", showType(v) ) - .atPos(v.determinePos(pos)) + .atPos(pos) .debugThrow(); } return out; diff --git a/tests/functional/lang/eval-fail-toJSON-nested.err.exp b/tests/functional/lang/eval-fail-toJSON-nested.err.exp new file mode 100644 index 000000000..1dbbdcd81 --- /dev/null +++ b/tests/functional/lang/eval-fail-toJSON-nested.err.exp @@ -0,0 +1,18 @@ +error: + … while calling the 'toJSON' builtin + at /pwd/lang/eval-fail-toJSON-nested.nix:1:1: + 1| builtins.toJSON { foo = a: 1; } + | ^ + 2| + + … while evaluating attribute 'foo' + at /pwd/lang/eval-fail-toJSON-nested.nix:1:19: + 1| builtins.toJSON { foo = a: 1; } + | ^ + 2| + + error: cannot convert a function to JSON + at /pwd/lang/eval-fail-toJSON-nested.nix:1:19: + 1| builtins.toJSON { foo = a: 1; } + | ^ + 2| diff --git a/tests/functional/lang/eval-fail-toJSON-nested.nix b/tests/functional/lang/eval-fail-toJSON-nested.nix new file mode 100644 index 000000000..46cab20cb --- /dev/null +++ b/tests/functional/lang/eval-fail-toJSON-nested.nix @@ -0,0 +1 @@ +builtins.toJSON { foo = a: 1; }