From 275b95c873bdc664e5a0f4799ffbf983a9a13ae5 Mon Sep 17 00:00:00 2001 From: eldritch horrors Date: Tue, 29 Apr 2025 14:10:53 +0200 Subject: [PATCH] libexpr: make ExprInheritFrom not be an ExprVar this was only a convenient fiction when it was introduced, but it is no longer. Change-Id: I72c50e7774c75408c1a40aee7da22059474ba01d --- lix/libexpr/eval.cc | 8 ++++++++ lix/libexpr/nixexpr.hh | 11 ++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lix/libexpr/eval.cc b/lix/libexpr/eval.cc index 564b0ab8a..83bc533a4 100644 --- a/lix/libexpr/eval.cc +++ b/lix/libexpr/eval.cc @@ -1259,6 +1259,14 @@ void ExprVar::eval(EvalState & state, Env & env, Value & v) } +void ExprInheritFrom::eval(EvalState & state, Env & env, Value & v) +{ + Value * v2 = env.values[displ]; + state.forceValue(*v2, pos); + v = *v2; +} + + static std::string showAttrPath(EvalState & state, Env & env, const AttrPath & attrPath) { std::ostringstream out; diff --git a/lix/libexpr/nixexpr.hh b/lix/libexpr/nixexpr.hh index 663f48cb0..efefa190d 100644 --- a/lix/libexpr/nixexpr.hh +++ b/lix/libexpr/nixexpr.hh @@ -138,20 +138,17 @@ struct ExprVar : Expr * Unlike normal variable references, the displacement is set during parsing, and always refers to * `ExprAttrs::inheritFromExprs` (by itself or in `ExprLet`), whose values are put into their own `Env`. */ -struct ExprInheritFrom : ExprVar +struct ExprInheritFrom : Expr { ref fromExpr; + Displacement displ; ExprInheritFrom(PosIdx pos, Displacement displ, ref fromExpr) - : ExprVar(pos, {}), fromExpr(fromExpr) + : Expr(pos), fromExpr(fromExpr), displ(displ) { - this->level = 0; - this->displ = displ; - this->fromWith = nullptr; } - JSON toJSON(SymbolTable const & symbols) const override; - void bindVars(Evaluator & es, const std::shared_ptr & env) override; + COMMON_METHODS }; struct ExprSelect : Expr