diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 71834f10f..ab3f7b3ff 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -1368,7 +1368,7 @@ void ExprVar::eval(EvalState & state, Env & env, Value & v) v = *v2; } -static std::string showAttrPath(EvalState & state, Env & env, std::span attrPath) +static std::string showAttrSelectionPath(EvalState & state, Env & env, std::span attrPath) { std::ostringstream out; bool first = true; @@ -1404,7 +1404,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v) env, getPos(), "while evaluating the attribute '%1%'", - showAttrPath(state, env, getAttrPath())) + showAttrSelectionPath(state, env, getAttrPath())) : nullptr; for (auto & i : getAttrPath()) { @@ -1445,7 +1445,7 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v) auto origin = std::get_if(&pos2r.origin); if (!(origin && *origin == state.derivationInternal)) state.addErrorTrace( - e, pos2, "while evaluating the attribute '%1%'", showAttrPath(state, env, getAttrPath())); + e, pos2, "while evaluating the attribute '%1%'", showAttrSelectionPath(state, env, getAttrPath())); } throw; } diff --git a/src/libexpr/include/nix/expr/nixexpr.hh b/src/libexpr/include/nix/expr/nixexpr.hh index c7bfb7359..df39ecdde 100644 --- a/src/libexpr/include/nix/expr/nixexpr.hh +++ b/src/libexpr/include/nix/expr/nixexpr.hh @@ -87,9 +87,9 @@ struct AttrName static_assert(std::is_trivially_copy_constructible_v); -typedef std::vector AttrPath; +typedef std::vector AttrSelectionPath; -std::string showAttrPath(const SymbolTable & symbols, std::span attrPath); +std::string showAttrSelectionPath(const SymbolTable & symbols, std::span attrPath); using UpdateQueue = SmallTemporaryValueVector; diff --git a/src/libexpr/include/nix/expr/parser-state.hh b/src/libexpr/include/nix/expr/parser-state.hh index 5a94f62e8..f9bd06589 100644 --- a/src/libexpr/include/nix/expr/parser-state.hh +++ b/src/libexpr/include/nix/expr/parser-state.hh @@ -163,20 +163,25 @@ struct ParserState static constexpr Expr::AstSymbols s = StaticEvalSymbols::create().exprSymbols; const EvalSettings & settings; - void dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos); + void dupAttr(const AttrSelectionPath & attrPath, const PosIdx pos, const PosIdx prevPos); void dupAttr(Symbol attr, const PosIdx pos, const PosIdx prevPos); void addAttr( - ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc); - void addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def); + ExprAttrs * attrs, + AttrSelectionPath && attrPath, + const ParserLocation & loc, + Expr * e, + const ParserLocation & exprLoc); + void addAttr(ExprAttrs * attrs, AttrSelectionPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def); void validateFormals(FormalsBuilder & formals, PosIdx pos = noPos, Symbol arg = {}); Expr * stripIndentation(const PosIdx pos, std::span>> es); PosIdx at(const ParserLocation & loc); }; -inline void ParserState::dupAttr(const AttrPath & attrPath, const PosIdx pos, const PosIdx prevPos) +inline void ParserState::dupAttr(const AttrSelectionPath & attrPath, const PosIdx pos, const PosIdx prevPos) { throw ParseError( - {.msg = HintFmt("attribute '%1%' already defined at %2%", showAttrPath(symbols, attrPath), positions[prevPos]), + {.msg = HintFmt( + "attribute '%1%' already defined at %2%", showAttrSelectionPath(symbols, attrPath), positions[prevPos]), .pos = positions[pos]}); } @@ -188,9 +193,13 @@ inline void ParserState::dupAttr(Symbol attr, const PosIdx pos, const PosIdx pre } inline void ParserState::addAttr( - ExprAttrs * attrs, AttrPath && attrPath, const ParserLocation & loc, Expr * e, const ParserLocation & exprLoc) + ExprAttrs * attrs, + AttrSelectionPath && attrPath, + const ParserLocation & loc, + Expr * e, + const ParserLocation & exprLoc) { - AttrPath::iterator i; + AttrSelectionPath::iterator i; // All attrpaths have at least one attr assert(!attrPath.empty()); auto pos = at(loc); @@ -236,7 +245,7 @@ inline void ParserState::addAttr( * symbol as its last element. */ inline void -ParserState::addAttr(ExprAttrs * attrs, AttrPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def) +ParserState::addAttr(ExprAttrs * attrs, AttrSelectionPath & attrPath, const Symbol & symbol, ExprAttrs::AttrDef && def) { ExprAttrs::AttrDefs::iterator j = attrs->attrs->find(symbol); if (j != attrs->attrs->end()) { diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index fc8c71b07..4a2f71a11 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -57,7 +57,7 @@ void ExprSelect::show(const SymbolTable & symbols, std::ostream & str) const { str << "("; e->show(symbols, str); - str << ")." << showAttrPath(symbols, getAttrPath()); + str << ")." << showAttrSelectionPath(symbols, getAttrPath()); if (def) { str << " or ("; def->show(symbols, str); @@ -69,7 +69,7 @@ void ExprOpHasAttr::show(const SymbolTable & symbols, std::ostream & str) const { str << "(("; e->show(symbols, str); - str << ") ? " << showAttrPath(symbols, attrPath) << ")"; + str << ") ? " << showAttrSelectionPath(symbols, attrPath) << ")"; } void ExprAttrs::showBindings(const SymbolTable & symbols, std::ostream & str) const @@ -261,7 +261,7 @@ void ExprPos::show(const SymbolTable & symbols, std::ostream & str) const str << "__curPos"; } -std::string showAttrPath(const SymbolTable & symbols, std::span attrPath) +std::string showAttrSelectionPath(const SymbolTable & symbols, std::span attrPath) { std::ostringstream out; bool first = true; diff --git a/src/nix/flake.cc b/src/nix/flake.cc index be19b5317..e88a5d46c 100644 --- a/src/nix/flake.cc +++ b/src/nix/flake.cc @@ -418,7 +418,7 @@ struct CmdFlakeCheck : FlakeCommand return std::nullopt; }; - std::map> attrPathsByDrv; + std::map> attrPathsByDrv; auto checkApp = [&](const std::string & attrPath, Value & v, const PosIdx pos) { try { @@ -618,7 +618,7 @@ struct CmdFlakeCheck : FlakeCommand }; // Build and store the attribute path for error reporting - AttrPath attrPath; + AttrSelectionPath attrPath; attrPath.push_back(AttrName(state->symbols.create(name))); attrPath.push_back(AttrName(attr.name)); attrPath.push_back(AttrName(attr2.name)); @@ -820,7 +820,7 @@ struct CmdFlakeCheck : FlakeCommand auto it = attrPathsByDrv.find(result.path); if (it != attrPathsByDrv.end() && !it->second.empty()) { for (auto & attrPath : it->second) { - auto attrPathStr = showAttrPath(state->symbols, attrPath); + auto attrPathStr = showAttrSelectionPath(state->symbols, attrPath); reportError(Error( "failed to build attribute '%s', build of '%s' failed: %s", attrPathStr,