Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/libexpr/eval.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,7 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
been substituted into the bodies of the other attributes.
Hence we need __overrides.) */
if (hasOverrides) {
Value * vOverrides = (*bindings.bindings)[overrides->second.displ].value;
Value * vOverrides = (*bindings.bindings)[std::distance(attrs.begin(), overrides)].value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Accidental complexity jump here. Also can we add a bit more tests for __overrides feature?

state.forceAttrs(
*vOverrides,
[&]() { return vOverrides->determinePos(noPos); },
Expand All @@ -1247,8 +1247,8 @@ void ExprAttrs::eval(EvalState & state, Env & env, Value & v)
for (auto & i : *vOverrides->attrs()) {
AttrDefs::iterator j = attrs.find(i.name);
if (j != attrs.end()) {
(*bindings.bindings)[j->second.displ] = i;
env2.values[j->second.displ] = i.value;
(*bindings.bindings)[std::distance(attrs.begin(), j)] = i;
env2.values[std::distance(attrs.begin(), j)] = i.value;
} else
bindings.push_back(i);
}
Expand Down
7 changes: 3 additions & 4 deletions src/libexpr/include/nix/expr/nixexpr.hh
Original file line number Diff line number Diff line change
Expand Up @@ -382,13 +382,12 @@ struct ExprAttrs : Expr
};

Kind kind;
Expr * e;
PosIdx pos;
Displacement displ = 0; // displacement
Expr * e;
AttrDef(Expr * e, const PosIdx & pos, Kind kind = Kind::Plain)
: kind(kind)
, e(e)
, pos(pos) {};
, pos(pos)
, e(e) {};
AttrDef() {};

template<typename T>
Expand Down
4 changes: 2 additions & 2 deletions src/libexpr/nixexpr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ void ExprAttrs::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>

Displacement displ = 0;
for (auto & i : attrs)
newEnv->vars.emplace_back(i.first, i.second.displ = displ++);
newEnv->vars.emplace_back(i.first, displ++);
return newEnv;
}();

Expand Down Expand Up @@ -490,7 +490,7 @@ void ExprLet::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv> &

Displacement displ = 0;
for (auto & i : attrs->attrs)
newEnv->vars.emplace_back(i.first, i.second.displ = displ++);
newEnv->vars.emplace_back(i.first, displ++);
return newEnv;
}();

Expand Down
Loading