diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 418f888b3..981bf201b 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -144,7 +144,10 @@ struct ExprVar : Expr */ struct ExprInheritFrom : ExprVar { - ExprInheritFrom(PosIdx pos, Displacement displ): ExprVar(pos, {}) + std::shared_ptr fromExpr; + + ExprInheritFrom(PosIdx pos, Displacement displ, std::shared_ptr fromExpr) + : ExprVar(pos, {}), fromExpr(fromExpr) { this->level = 0; this->displ = displ; @@ -222,7 +225,7 @@ struct ExprAttrs : Expr }; 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/src/libexpr/parser/parser.cc b/src/libexpr/parser/parser.cc index 850f1276e..a5a6c0f85 100644 --- a/src/libexpr/parser/parser.cc +++ b/src/libexpr/parser/parser.cc @@ -317,18 +317,23 @@ template<> struct BuildAST : change_head { }); } } - if (auto fromE = std::move(s.from)) { + if (s.from != nullptr) { if (!b.attrs.inheritFromExprs) - b.attrs.inheritFromExprs = std::make_unique>>(); - b.attrs.inheritFromExprs->push_back(std::move(fromE)); + b.attrs.inheritFromExprs = std::make_unique>>(); + std::shared_ptr fromExpr = std::move(s.from); + b.attrs.inheritFromExprs->push_back(fromExpr); for (auto & [i, iPos] : s.attrs) { if (attrs.find(i.symbol) != attrs.end()) ps.dupAttr(i.symbol, iPos, attrs[i.symbol].pos); - auto from = std::make_unique(s.fromPos, b.attrs.inheritFromExprs->size() - 1); + auto inheritFrom = std::make_unique( + s.fromPos, + b.attrs.inheritFromExprs->size() - 1, + fromExpr + ); attrs.emplace( i.symbol, ExprAttrs::AttrDef( - std::make_unique(iPos, std::move(from), i.symbol), + std::make_unique(iPos, std::move(inheritFrom), i.symbol), iPos, ExprAttrs::AttrDef::Kind::InheritedFrom)); } diff --git a/src/libexpr/parser/state.hh b/src/libexpr/parser/state.hh index f5a0428d7..b26f01fb6 100644 --- a/src/libexpr/parser/state.hh +++ b/src/libexpr/parser/state.hh @@ -103,7 +103,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.