diff --git a/lix/libexpr/nixexpr.cc b/lix/libexpr/nixexpr.cc index d09f9eee0..242334a5f 100644 --- a/lix/libexpr/nixexpr.cc +++ b/lix/libexpr/nixexpr.cc @@ -130,12 +130,19 @@ void ExprAttrs::addBindingsToJSON(JSON & out, const SymbolTable & symbols) const } } + std::vector inheritFromExprs; + if (this->inheritFromExprs) { + for (auto & e : *this->inheritFromExprs) { + inheritFromExprs.push_back(e.get()); + } + } + for (const auto & [from, syms] : inheritsFrom) { JSON attrs = JSON::array(); for (auto sym : syms) attrs.push_back(symbols[sym]); out["inheritFrom"].push_back({ - {"from", (*inheritFromExprs)[from]->toJSON(symbols)}, + {"from", inheritFromExprs[from]->toJSON(symbols)}, {"attrs", attrs} }); } diff --git a/lix/libexpr/nixexpr.hh b/lix/libexpr/nixexpr.hh index 044d56db9..ee60d1a9e 100644 --- a/lix/libexpr/nixexpr.hh +++ b/lix/libexpr/nixexpr.hh @@ -151,10 +151,10 @@ struct ExprVar : Expr */ struct ExprInheritFrom : Expr { - ref fromExpr; + Expr & fromExpr; Displacement displ; - ExprInheritFrom(PosIdx pos, Displacement displ, ref fromExpr) + ExprInheritFrom(PosIdx pos, Displacement displ, Expr & fromExpr) : Expr(pos), fromExpr(fromExpr), displ(displ) { } @@ -238,7 +238,7 @@ struct ExprAttrs }; typedef std::map AttrDefs; AttrDefs attrs; - std::unique_ptr>> inheritFromExprs; + std::unique_ptr>> inheritFromExprs; struct DynamicAttrDef { std::unique_ptr nameExpr, valueExpr; PosIdx pos; diff --git a/lix/libexpr/parser/parser-impl1.inc.cc b/lix/libexpr/parser/parser-impl1.inc.cc index bfa3115d3..d698daddb 100644 --- a/lix/libexpr/parser/parser-impl1.inc.cc +++ b/lix/libexpr/parser/parser-impl1.inc.cc @@ -398,16 +398,16 @@ template<> struct BuildAST : change_head { } if (s.from != nullptr) { if (!b.attrs.inheritFromExprs) - b.attrs.inheritFromExprs = std::make_unique>>(); - auto fromExpr = ref::unsafeFromPtr(std::move(s.from)); - b.attrs.inheritFromExprs->push_back(fromExpr); + b.attrs.inheritFromExprs = std::make_unique>>(); + b.attrs.inheritFromExprs->push_back(std::move(s.from)); + auto & fromExpr = b.attrs.inheritFromExprs->back(); for (auto & i : s.attrs) { if (attrs.find(i.symbol) != attrs.end()) ps.dupAttr(i.symbol, i.pos, attrs[i.symbol].pos); auto inheritFrom = std::make_unique( s.fromPos, b.attrs.inheritFromExprs->size() - 1, - fromExpr + *fromExpr ); attrs.emplace( i.symbol, diff --git a/lix/libexpr/parser/state.hh b/lix/libexpr/parser/state.hh index 5250ba1fa..af2e0eb37 100644 --- a/lix/libexpr/parser/state.hh +++ b/lix/libexpr/parser/state.hh @@ -173,7 +173,7 @@ inline void State::addAttr(ExprAttrs * attrs, AttrPath && attrPath, std::unique_ auto * jAttrs = dynamic_cast(j->second.e.get()); if (jAttrs && ae) { if (ae->inheritFromExprs && !jAttrs->inheritFromExprs) - jAttrs->inheritFromExprs = std::make_unique>>(); + jAttrs->inheritFromExprs = std::make_unique>>(); for (auto & ad : ae->attrs) { auto j2 = jAttrs->attrs.find(ad.first); if (j2 != jAttrs->attrs.end()) // Attr already defined in iAttrs, error.