From 658404c2a004b2d369c9cb667f7a1c7f0db3f563 Mon Sep 17 00:00:00 2001 From: skye Date: Fri, 3 Apr 2026 13:48:26 -0400 Subject: [PATCH] libexpr/json-to-value: Migrate parseJSON to return a Value Part of #1136 Change-Id: I5ac23ce461a106360b150e64a6bc0f2f6a6a6964 --- lix/libexpr/json-to-value.cc | 4 ++-- lix/libexpr/json-to-value.hh | 3 +-- lix/libexpr/primops.cc | 2 +- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lix/libexpr/json-to-value.cc b/lix/libexpr/json-to-value.cc index 55aa5d374..81899d68a 100644 --- a/lix/libexpr/json-to-value.cc +++ b/lix/libexpr/json-to-value.cc @@ -190,13 +190,13 @@ public: } }; -void parseJSON(EvalState & state, const std::string_view & s_, Value & v) +Value parseJSON(EvalState & state, const std::string_view & s_) { JSONSax parser(state); bool res = JSON::sax_parse(s_, &parser); if (!res) throw JSONParseError("Invalid JSON Value"); - v = parser.result(); + return parser.result(); } } diff --git a/lix/libexpr/json-to-value.hh b/lix/libexpr/json-to-value.hh index ab66284a1..fc14b418b 100644 --- a/lix/libexpr/json-to-value.hh +++ b/lix/libexpr/json-to-value.hh @@ -12,6 +12,5 @@ struct Value; MakeError(JSONParseError, Error); -void parseJSON(EvalState & state, const std::string_view & s, Value & v); - +Value parseJSON(EvalState & state, const std::string_view & s); } diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index 1b0ce2b8e..2b3b8e302 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -1622,7 +1622,7 @@ static void prim_fromJSON(EvalState & state, Value * * args, Value & v) { auto s = state.forceStringNoCtx(*args[0], noPos, "while evaluating the first argument passed to builtins.fromJSON"); try { - parseJSON(state, s, v); + v = parseJSON(state, s); } catch (JSONParseError &e) { e.addTrace(nullptr, "while decoding a JSON string"); throw;