libexpr: use StorePath::to_string in string contexts

`path.abs()` does the same thing, but `to_string` communicates intent as well.

Change-Id: I9619a9f2e32317f0a1cc8e092ce8898471b980ac
This commit is contained in:
eldritch horrors
2025-01-10 15:20:27 -08:00
committed by Jade Lovelace
parent 44255c316d
commit 3acba7951a
5 changed files with 6 additions and 6 deletions
+1 -1
View File
@@ -138,7 +138,7 @@ static void getAllExprs(Evaluator & state,
attrName = std::string(attrName, 0, attrName.size() - 4);
if (!seen.insert(attrName).second) {
std::string suggestionMessage = "";
if (path2.path.abs().find("channels") != std::string::npos && path.path.abs().find("channels") != std::string::npos)
if (path2.to_string().find("channels") != std::string::npos && path.to_string().find("channels") != std::string::npos)
suggestionMessage = fmt("\nsuggestion: remove '%s' from either the root channels or the user channels", attrName);
printError("warning: name collision in input Nix expressions, skipping '%1%'"
"%2%", path2, suggestionMessage);
+2 -2
View File
@@ -805,7 +805,7 @@ void EvalState::mkPos(Value & v, PosIdx p)
auto origin = ctx.positions.originOf(p);
if (auto path = std::get_if<SourcePath>(&origin)) {
auto attrs = ctx.buildBindings(3);
attrs.alloc(ctx.s.file).mkString(path->path.abs());
attrs.alloc(ctx.s.file).mkString(path->to_string());
makePositionThunks(*this, p, attrs.alloc(ctx.s.line), attrs.alloc(ctx.s.column));
v.mkAttrs(attrs);
} else
@@ -2269,7 +2269,7 @@ BackedStringView EvalState::coerceToString(
v._path
: copyToStore
? ctx.store->printStorePath(ctx.paths.copyPathToStore(context, v.path(), ctx.repair))
: std::string(v.path().path.abs());
: v.path().to_string();
}
if (v.type() == nAttrs) {
+1 -1
View File
@@ -1153,7 +1153,7 @@ static void prim_toPath(EvalState & state, const PosIdx pos, Value * * args, Val
{
NixStringContext context;
auto path = state.coerceToPath(pos, *args[0], context, "while evaluating the first argument passed to builtins.toPath");
v.mkString(path.path.abs(), context);
v.mkString(path.to_string(), context);
}
/* Allow a valid store path to be used in an expression. This is
+1 -1
View File
@@ -39,7 +39,7 @@ json printValueAsJSON(EvalState & state, bool strict,
out = state.ctx.store->printStorePath(
state.ctx.paths.copyPathToStore(context, v.path(), state.ctx.repair));
else
out = v.path().path.abs();
out = v.path().to_string();
break;
case nNull:
+1 -1
View File
@@ -22,7 +22,7 @@ static void printValueAsXML(EvalState & state, bool strict, bool location,
static void posToXML(EvalState & state, XMLAttrs & xmlAttrs, const Pos & pos)
{
if (auto path = std::get_if<SourcePath>(&pos.origin))
xmlAttrs["path"] = path->path.abs();
xmlAttrs["path"] = path->to_string();
xmlAttrs["line"] = fmt("%1%", pos.line);
xmlAttrs["column"] = fmt("%1%", pos.column);
}