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 ++++++++++----- 9 files changed, 40 insertions(+), 39 deletions(-) (limited to 'third_party/nix/src/libexpr') 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; } -- cgit 1.4.1