From 09cbc431cca08be891e5e792ceda2a34956b2fc8 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Tue, 19 May 2020 18:01:12 +0100 Subject: fix(3p/nix): Fix incorrectly braced conditionals and loops Fixes mistakes introduced by clang-tidy in the previous commit. --- third_party/nix/src/libexpr/eval.cc | 18 ++++++------------ third_party/nix/src/libexpr/get-drvs.cc | 7 +++---- third_party/nix/src/libexpr/json-to-value.cc | 3 +-- third_party/nix/src/libexpr/names.cc | 3 +-- third_party/nix/src/libexpr/nixexpr.cc | 20 ++++++++++++++------ third_party/nix/src/libexpr/primops.cc | 7 +++---- third_party/nix/src/libexpr/primops/fetchGit.cc | 3 +-- .../nix/src/libexpr/primops/fetchMercurial.cc | 3 +-- third_party/nix/src/libexpr/value-to-xml.cc | 15 ++++++++++----- third_party/nix/src/libmain/shared.hh | 4 ++-- third_party/nix/src/libstore/sqlite.cc | 3 +-- third_party/nix/src/nix-daemon/nix-daemon.cc | 3 +-- .../nix/src/nix-instantiate/nix-instantiate.cc | 9 +++++---- third_party/nix/src/nix/installables.cc | 5 ++--- third_party/nix/src/nix/ls.cc | 13 ++++++++----- third_party/nix/src/nix/repl.cc | 7 +++---- 16 files changed, 62 insertions(+), 61 deletions(-) (limited to 'third_party/nix/src') diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index 19f6a46ed655..5d6f30c07d0c 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -820,15 +820,12 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& v) { newBnds->sort(); v.attrs = newBnds; } + } else { + for (auto& i : attrs) + v.attrs->push_back( + Attr(i.first, i.second.e->maybeThunk(state, env), &i.second.pos)); } - else { - for - } - (auto& i - : attrs) v.attrs->push_back(Attr(i.first, i.second.e->maybeThunk(state, env), - &i.second.pos)); - /* Dynamic attrs apply *after* rec and __overrides. */ for (auto& i : dynamicAttrs) { Value nameVal; @@ -1350,9 +1347,8 @@ void ExprConcatStrings::eval(EvalState& state, Env& env, Value& v) { auto path = canonPath(s.str()); mkPath(v, path.c_str()); } else { - mkString + mkString(v, s.str(), context); } - (v, s.str(), context); } void ExprPos::eval(EvalState& state, Env& env, Value& v) { @@ -1378,9 +1374,7 @@ void EvalState::forceValueDeep(Value& v) { i.name, *i.pos); throw; } - } - - else if (v.isList()) { + } else if (v.isList()) { for (size_t n = 0; n < v.listSize(); ++n) recurse(*v.listElems()[n]); } }; diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc index 16bb03f1d16f..ad7211eaea5b 100644 --- a/third_party/nix/src/libexpr/get-drvs.cc +++ b/third_party/nix/src/libexpr/get-drvs.cc @@ -387,11 +387,10 @@ static void getDerivations(EvalState& state, Value& vIn, } else { - throw + throw TypeError( + "expression does not evaluate to a derivation (or a set or list of " + "those)"); } - TypeError( - "expression does not evaluate to a derivation (or a set or list of " - "those)"); } void getDerivations(EvalState& state, Value& v, const string& pathPrefix, diff --git a/third_party/nix/src/libexpr/json-to-value.cc b/third_party/nix/src/libexpr/json-to-value.cc index e7c7794d1181..8d84a5ac6901 100644 --- a/third_party/nix/src/libexpr/json-to-value.cc +++ b/third_party/nix/src/libexpr/json-to-value.cc @@ -42,9 +42,8 @@ static string parseJSONString(const char*& s) { throw JSONParseError("invalid escaped character in JSON string"); s++; } else { - res + res += *s++; } - += *s++; } s++; return res; diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc index 66a918de5dc2..f7752f2bf804 100644 --- a/third_party/nix/src/libexpr/names.cc +++ b/third_party/nix/src/libexpr/names.cc @@ -71,9 +71,8 @@ static bool componentsLT(const string& c1, const string& c2) { } else if (c1Num) { return false; } else { - return + return c1 < c2; } - c1 < c2; } int compareVersions(const string& v1, const string& v2) { diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc index 85e80361e3ab..9c25530efdba 100644 --- a/third_party/nix/src/libexpr/nixexpr.cc +++ b/third_party/nix/src/libexpr/nixexpr.cc @@ -256,16 +256,20 @@ void ExprAttrs::bindVars(const StaticEnv& env) { dynamicEnv = &newEnv; unsigned int displ = 0; - for (auto& i : attrs) newEnv.vars[i.first] = i.second.displ = displ++; + for (auto& i : attrs) { + newEnv.vars[i.first] = i.second.displ = displ++; + } - for (auto& i : attrs) + for (auto& i : attrs) { i.second.e->bindVars(i.second.inherited ? env : newEnv); + } } else { - for + for (auto& i : attrs) { + i.second.e->bindVars(env); + } } - (auto& i : attrs) i.second.e->bindVars(env); for (auto& i : dynamicAttrs) { i.nameExpr->bindVars(*dynamicEnv); @@ -282,10 +286,14 @@ void ExprLambda::bindVars(const StaticEnv& env) { unsigned int displ = 0; - if (!arg.empty()) newEnv.vars[arg] = displ++; + if (!arg.empty()) { + newEnv.vars[arg] = displ++; + } if (matchAttrs) { - for (auto& i : formals->formals) newEnv.vars[i.name] = displ++; + for (auto& i : formals->formals) { + newEnv.vars[i.name] = displ++; + } for (auto& i : formals->formals) if (i.def) i.def->bindVars(newEnv); diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 98a6f56dfdf3..3e11d6589f6a 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -1966,9 +1966,9 @@ static void prim_concatStringSep(EvalState& state, const Pos& pos, Value** args, if (first) { first = false; } else { - res + res += sep; } - += sep; + res += state.coerceToString(pos, *args[1]->listElems()[n], context); } @@ -2103,9 +2103,8 @@ void fetch(EvalState& state, const Pos& pos, Value** args, Value& v, throw EvalError(format("'url' argument required, at %1%") % pos); } else { - request + request.uri = state.forceStringNoCtx(*args[0], pos); } - .uri = state.forceStringNoCtx(*args[0], pos); state.checkURI(request.uri); diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc index af3f89fde77a..7fbd4dc92cf0 100644 --- a/third_party/nix/src/libexpr/primops/fetchGit.cc +++ b/third_party/nix/src/libexpr/primops/fetchGit.cc @@ -228,9 +228,8 @@ static void prim_fetchGit(EvalState& state, const Pos& pos, Value** args, throw EvalError(format("'url' argument required, at %1%") % pos); } else { - url + url = state.coerceToString(pos, *args[0], context, false, false); } - = state.coerceToString(pos, *args[0], context, false, false); // FIXME: git externals probably can be used to bypass the URI // whitelist. Ah well. diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc index 5847f6021f43..3de42fe770dc 100644 --- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc +++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc @@ -204,9 +204,8 @@ static void prim_fetchMercurial(EvalState& state, const Pos& pos, Value** args, throw EvalError(format("'url' argument required, at %1%") % pos); } else { - url + url = state.coerceToString(pos, *args[0], context, false, false); } - = state.coerceToString(pos, *args[0], context, false, false); // FIXME: git externals probably can be used to bypass the URI // whitelist. Ah well. diff --git a/third_party/nix/src/libexpr/value-to-xml.cc b/third_party/nix/src/libexpr/value-to-xml.cc index 5ea1e09824c7..6247d25b9c34 100644 --- a/third_party/nix/src/libexpr/value-to-xml.cc +++ b/third_party/nix/src/libexpr/value-to-xml.cc @@ -137,15 +137,20 @@ static void printValueAsXML(EvalState& state, bool strict, bool location, if (v.lambda.fun->matchAttrs) { XMLAttrs attrs; - if (!v.lambda.fun->arg.empty()) attrs["name"] = v.lambda.fun->arg; - if (v.lambda.fun->formals->ellipsis) attrs["ellipsis"] = "1"; + if (!v.lambda.fun->arg.empty()) { + attrs["name"] = v.lambda.fun->arg; + } + if (v.lambda.fun->formals->ellipsis) { + attrs["ellipsis"] = "1"; + } XMLOpenElement _(doc, "attrspat", attrs); - for (auto& i : v.lambda.fun->formals->formals) + for (auto& i : v.lambda.fun->formals->formals) { doc.writeEmptyElement("attr", singletonAttrs("name", i.name)); + } } else { - doc + doc.writeEmptyElement("varpat", + singletonAttrs("name", v.lambda.fun->arg)); } - .writeEmptyElement("varpat", singletonAttrs("name", v.lambda.fun->arg)); break; } diff --git a/third_party/nix/src/libmain/shared.hh b/third_party/nix/src/libmain/shared.hh index 337c38413da7..e5f4bec6482e 100644 --- a/third_party/nix/src/libmain/shared.hh +++ b/third_party/nix/src/libmain/shared.hh @@ -68,9 +68,9 @@ N getIntArg(const string& opt, Strings::iterator& i, } else if (u == 'T') { multiplier = 1ULL << 40; } else { - throw + throw UsageError(format("invalid unit specifier '%1%'") % u); } - UsageError(format("invalid unit specifier '%1%'") % u); + s.resize(s.size() - 1); } } diff --git a/third_party/nix/src/libstore/sqlite.cc b/third_party/nix/src/libstore/sqlite.cc index 81c3ffcd9d05..5aa661afe055 100644 --- a/third_party/nix/src/libstore/sqlite.cc +++ b/third_party/nix/src/libstore/sqlite.cc @@ -24,9 +24,8 @@ namespace nix { ? fmt("SQLite database '%s' is busy (SQLITE_PROTOCOL)", path) : fmt("SQLite database '%s' is busy", path)); } else { - throw + throw SQLiteError("%s: %s (in '%s')", fs.s, sqlite3_errstr(exterr), path); } - SQLiteError("%s: %s (in '%s')", fs.s, sqlite3_errstr(exterr), path); } SQLite::SQLite(const Path& path) { diff --git a/third_party/nix/src/nix-daemon/nix-daemon.cc b/third_party/nix/src/nix-daemon/nix-daemon.cc index dbc49edfade5..dde1c8457108 100644 --- a/third_party/nix/src/nix-daemon/nix-daemon.cc +++ b/third_party/nix/src/nix-daemon/nix-daemon.cc @@ -305,9 +305,8 @@ static void performOp(TunnelLogger* logger, ref store, bool trusted, ParseSink sink; /* null sink; just parse the NAR */ parseDump(sink, savedNAR); } else { - parseDump + parseDump(savedRegular, from); } - (savedRegular, from); logger->startWork(); if (!savedRegular.regular) throw Error("regular file expected"); diff --git a/third_party/nix/src/nix-instantiate/nix-instantiate.cc b/third_party/nix/src/nix-instantiate/nix-instantiate.cc index df97f23ef9c9..2630f5f9ebfc 100644 --- a/third_party/nix/src/nix-instantiate/nix-instantiate.cc +++ b/third_party/nix/src/nix-instantiate/nix-instantiate.cc @@ -163,7 +163,9 @@ static int _main(int argc, char** argv) { if (findFile) { for (auto& i : files) { Path p = state->findFile(i); - if (p == "") throw Error(format("unable to find '%1%'") % i); + if (p == "") { + throw Error(format("unable to find '%1%'") % i); + } std::cout << p << std::endl; } return 0; @@ -173,10 +175,9 @@ static int _main(int argc, char** argv) { Expr* e = state->parseStdin(); processExpr(*state, attrPaths, parseOnly, strict, autoArgs, evalOnly, outputKind, xmlOutputSourceLocation, e); - } else { - if + } else if (files.empty() && !fromArgs) { + files.push_back("./default.nix"); } - (files.empty() && !fromArgs) files.push_back("./default.nix"); for (auto& i : files) { Expr* e = fromArgs diff --git a/third_party/nix/src/nix/installables.cc b/third_party/nix/src/nix/installables.cc index f708a5a9fa14..2378a4b16a52 100644 --- a/third_party/nix/src/nix/installables.cc +++ b/third_party/nix/src/nix/installables.cc @@ -248,10 +248,9 @@ Buildables build(ref store, RealiseMode mode, if (mode == DryRun) { printMissing(store, pathsToBuild); - } else { - if + } else if (mode == Build) { + store->buildPaths(pathsToBuild); } - (mode == Build) store->buildPaths(pathsToBuild); return buildables; } diff --git a/third_party/nix/src/nix/ls.cc b/third_party/nix/src/nix/ls.cc index 68a2c203defa..62720b93a0ce 100644 --- a/third_party/nix/src/nix/ls.cc +++ b/third_party/nix/src/nix/ls.cc @@ -54,30 +54,33 @@ struct MixLs : virtual Args, MixJSON { const std::string& relPath, bool showDirectory) { if (st.type == FSAccessor::Type::tDirectory && !showDirectory) { auto names = accessor->readDirectory(curPath); - for (auto& name : names) + for (auto& name : names) { showFile(curPath + "/" + name, relPath + "/" + name); + } } else showFile(curPath, relPath); }; auto st = accessor->stat(path); - if (st.type == FSAccessor::Type::tMissing) + if (st.type == FSAccessor::Type::tMissing) { throw Error(format("path '%1%' does not exist") % path); + } doPath(st, path, st.type == FSAccessor::Type::tDirectory ? "." : baseNameOf(path), showDirectory); } void list(ref accessor) { - if (path == "/") path = ""; + if (path == "/") { + path = ""; + } if (json) { JSONPlaceholder jsonRoot(std::cout); listNar(jsonRoot, accessor, path, recursive); } else { - listText + listText(accessor); } - (accessor); } }; diff --git a/third_party/nix/src/nix/repl.cc b/third_party/nix/src/nix/repl.cc index a24020b7bac8..2d7188740515 100644 --- a/third_party/nix/src/nix/repl.cc +++ b/third_party/nix/src/nix/repl.cc @@ -689,9 +689,8 @@ std::ostream& NixRepl::printValue(std::ostream& str, Value& v, str << "}"; } else { - str + str << "{ ... }"; } - << "{ ... }"; break; } @@ -715,9 +714,9 @@ std::ostream& NixRepl::printValue(std::ostream& str, Value& v, str << " "; } } else { - str + str << "... "; } - << "... "; + str << "]"; break; -- cgit 1.4.1