mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
findAlongAttrPath(): Return position
(cherry picked from commit 0b013a54dc
)
This commit is contained in:
parent
1eb952d27a
commit
c1ca4f0acc
8 changed files with 14 additions and 11 deletions
|
@ -32,7 +32,7 @@ static Strings parseAttrPath(const string & s)
|
|||
}
|
||||
|
||||
|
||||
Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
||||
std::pair<Value *, Pos> findAlongAttrPath(EvalState & state, const string & attrPath,
|
||||
Bindings & autoArgs, Value & vIn)
|
||||
{
|
||||
Strings tokens = parseAttrPath(attrPath);
|
||||
|
@ -41,6 +41,7 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
|||
Error(format("attribute selection path '%1%' does not match expression") % attrPath);
|
||||
|
||||
Value * v = &vIn;
|
||||
Pos pos = noPos;
|
||||
|
||||
for (auto & attr : tokens) {
|
||||
|
||||
|
@ -72,6 +73,7 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
|||
if (a == v->attrs->end())
|
||||
throw AttrPathNotFound("attribute '%1%' in selection path '%2%' not found", attr, attrPath);
|
||||
v = &*a->value;
|
||||
pos = *a->pos;
|
||||
}
|
||||
|
||||
else if (apType == apIndex) {
|
||||
|
@ -85,11 +87,12 @@ Value * findAlongAttrPath(EvalState & state, const string & attrPath,
|
|||
throw AttrPathNotFound("list index %1% in selection path '%2%' is out of range", attrIndex, attrPath);
|
||||
|
||||
v = v->listElems()[attrIndex];
|
||||
pos = noPos;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return v;
|
||||
return {v, pos};
|
||||
}
|
||||
|
||||
|
||||
|
@ -98,7 +101,7 @@ Pos findDerivationFilename(EvalState & state, Value & v, std::string what)
|
|||
Value * v2;
|
||||
try {
|
||||
auto dummyArgs = state.allocBindings(0);
|
||||
v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v);
|
||||
v2 = findAlongAttrPath(state, "meta.position", *dummyArgs, v).first;
|
||||
} catch (Error &) {
|
||||
throw Error("package '%s' has no source location information", what);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue