diff --git a/lix/libexpr/eval-error.cc b/lix/libexpr/eval-error.cc index 23b318509..3b79288fa 100644 --- a/lix/libexpr/eval-error.cc +++ b/lix/libexpr/eval-error.cc @@ -14,7 +14,7 @@ EvalErrorBuilder & EvalErrorBuilder::withExitStatus(unsigned int exitStatu template EvalErrorBuilder & EvalErrorBuilder::atPos(PosIdx pos) { - error.err.pos = error.state.positions[pos]; + error.err.pos = state.positions[pos]; return *this; } @@ -28,7 +28,7 @@ template EvalErrorBuilder & EvalErrorBuilder::withTrace(PosIdx pos, const std::string_view text) { error.err.traces.push_front( - Trace{.pos = error.state.positions[pos], .hint = HintFmt(std::string(text))}); + Trace{.pos = state.positions[pos], .hint = HintFmt(std::string(text))}); return *this; } @@ -42,9 +42,9 @@ EvalErrorBuilder & EvalErrorBuilder::withSuggestions(Suggestions & s) template EvalErrorBuilder & EvalErrorBuilder::withFrame(const Env & env, const Expr & expr) { - if (error.state.debug) { - error.frame = error.state.debug->addTrace(DebugTrace{ - .pos = error.state.positions[expr.getPos()], + if (state.debug) { + error.frame = state.debug->addTrace(DebugTrace{ + .pos = state.positions[expr.getPos()], .expr = expr, .env = env, .hint = HintFmt("Fake frame for debugging purposes"), @@ -57,7 +57,7 @@ EvalErrorBuilder & EvalErrorBuilder::withFrame(const Env & env, const Expr template EvalErrorBuilder & EvalErrorBuilder::addTrace(PosIdx pos, HintFmt hint) { - error.addTrace(error.state.positions[pos], hint); + error.addTrace(state.positions[pos], hint); return *this; } @@ -67,18 +67,18 @@ EvalErrorBuilder & EvalErrorBuilder::addTrace(PosIdx pos, std::string_view formatString, const Args &... formatArgs) { - addTrace(error.state.positions[pos], HintFmt(std::string(formatString), formatArgs...)); + addTrace(state.positions[pos], HintFmt(std::string(formatString), formatArgs...)); return *this; } template void EvalErrorBuilder::debugThrow() { - if (error.state.debug) { - if (auto last = error.state.debug->traces().next()) { + if (state.debug) { + if (auto last = state.debug->traces().next()) { const Env * env = &(*last)->env; const Expr * expr = &(*last)->expr; - error.state.debug->runDebugRepl(error.state, &error, *env, *expr); + state.debug->runDebugRepl(state, &error, *env, *expr); } } diff --git a/lix/libexpr/eval-error.hh b/lix/libexpr/eval-error.hh index 2c18ebc06..b05feb827 100644 --- a/lix/libexpr/eval-error.hh +++ b/lix/libexpr/eval-error.hh @@ -24,20 +24,7 @@ class EvalError : public Error std::shared_ptr frame; public: - EvalState & state; - - EvalError(EvalState & state, ErrorInfo && errorInfo) - : Error(errorInfo) - , state(state) - { - } - - template - explicit EvalError(EvalState & state, const std::string & formatString, const Args &... formatArgs) - : Error(formatString, formatArgs...) - , state(state) - { - } + using Error::Error; }; MakeError(ParseError, Error); @@ -58,8 +45,8 @@ struct InvalidPathError : public EvalError { public: Path path; - InvalidPathError(EvalState & state, const Path & path) - : EvalError(state, "path '%s' did not exist in the store during evaluation", path) + InvalidPathError(const Path & path) + : EvalError("path '%s' did not exist in the store during evaluation", path) { } }; @@ -74,9 +61,11 @@ class EvalErrorBuilder final { friend class EvalState; + EvalState & state; + template explicit EvalErrorBuilder(EvalState & state, const Args &... args) - : error(T(state, args...)) + : state(state), error(T(args...)) { } diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index 64a26dc60..3934c9ba9 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -567,7 +567,7 @@ static void prim_genericClosure(EvalState & state, const PosIdx pos, Value * * a static void prim_break(EvalState & state, const PosIdx pos, Value * * args, Value & v) { if (auto trace = state.debug ? state.debug->traces().next() : std::nullopt) { - auto error = EvalError(state, ErrorInfo { + auto error = EvalError(ErrorInfo { .level = lvlInfo, .msg = HintFmt("breakpoint reached"), .pos = state.positions[pos],