minor cleanup

This commit is contained in:
Ben Burdette 2022-04-08 15:46:12 -06:00
parent a86c2a8481
commit 27d45f9eb3
4 changed files with 29 additions and 34 deletions

View file

@ -547,8 +547,6 @@ bool NixRepl::processLine(std::string line)
loadDebugTraceEnv(*iter); loadDebugTraceEnv(*iter);
break; break;
} }
// std::cout << "\n" << ANSI_BLUE << idx << ANSI_NORMAL << ": ";
// showDebugTrace(std::cout, *iter);
} }
} }
else if (arg == "step") { else if (arg == "step") {

View file

@ -789,6 +789,7 @@ void mapStaticEnvBindings(const StaticEnv &se, const Env &env, valmap & vm)
auto map = valmap(); auto map = valmap();
if (env.type == Env::HasWithAttrs) if (env.type == Env::HasWithAttrs)
{ {
// add 'with' bindings.
Bindings::iterator j = env.values[0]->attrs->begin(); Bindings::iterator j = env.values[0]->attrs->begin();
while (j != env.values[0]->attrs->end()) { while (j != env.values[0]->attrs->end()) {
map[j->name] = j->value; map[j->name] = j->value;
@ -1485,15 +1486,15 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
try { try {
auto dts = auto dts =
debuggerHook ? debuggerHook ?
makeDebugTraceStacker( makeDebugTraceStacker(
state, state,
*this, *this,
env, env,
*pos2, *pos2,
"while evaluating the attribute '%1%'", "while evaluating the attribute '%1%'",
showAttrPath(state, env, attrPath)) showAttrPath(state, env, attrPath))
: nullptr; : nullptr;
for (auto & i : attrPath) { for (auto & i : attrPath) {
state.nrLookups++; state.nrLookups++;
@ -2082,13 +2083,13 @@ void EvalState::forceValueDeep(Value & v)
try { try {
auto dts = auto dts =
debuggerHook ? debuggerHook ?
// if the value is a thunk, we're evaling. otherwise no trace necessary. // if the value is a thunk, we're evaling. otherwise no trace necessary.
(i.value->isThunk() ? (i.value->isThunk() ?
makeDebugTraceStacker(*this, *v.thunk.expr, *v.thunk.env, *i.pos, makeDebugTraceStacker(*this, *v.thunk.expr, *v.thunk.env, *i.pos,
"while evaluating the attribute '%1%'", i.name) "while evaluating the attribute '%1%'", i.name)
: nullptr) : nullptr)
: nullptr; : nullptr;
recurse(*i.value); recurse(*i.value);
} catch (Error & e) { } catch (Error & e) {
@ -2123,8 +2124,7 @@ NixFloat EvalState::forceFloat(Value & v, const Pos & pos)
if (v.type() == nInt) if (v.type() == nInt)
return v.integer; return v.integer;
else if (v.type() != nFloat) else if (v.type() != nFloat)
throwTypeError(pos, "value is %1% while a float was expected", v, throwTypeError(pos, "value is %1% while a float was expected", v, *this);
*this);
return v.fpoint; return v.fpoint;
} }
@ -2133,8 +2133,7 @@ bool EvalState::forceBool(Value & v, const Pos & pos)
{ {
forceValue(v, pos); forceValue(v, pos);
if (v.type() != nBool) if (v.type() != nBool)
throwTypeError(pos, "value is %1% while a Boolean was expected", v, throwTypeError(pos, "value is %1% while a Boolean was expected", v, *this);
*this);
return v.boolean; return v.boolean;
} }
@ -2149,8 +2148,7 @@ void EvalState::forceFunction(Value & v, const Pos & pos)
{ {
forceValue(v, pos); forceValue(v, pos);
if (v.type() != nFunction && !isFunctor(v)) if (v.type() != nFunction && !isFunctor(v))
throwTypeError(pos, "value is %1% while a function was expected", v, throwTypeError(pos, "value is %1% while a function was expected", v, *this);
*this);
} }
@ -2158,8 +2156,7 @@ std::string_view EvalState::forceString(Value & v, const Pos & pos)
{ {
forceValue(v, pos); forceValue(v, pos);
if (v.type() != nString) { if (v.type() != nString) {
throwTypeError(pos, "value is %1% while a string was expected", v, throwTypeError(pos, "value is %1% while a string was expected", v, *this);
*this);
} }
return v.string.s; return v.string.s;
} }

View file

@ -23,7 +23,6 @@
#include "nixexpr.hh" #include "nixexpr.hh"
#include "eval.hh" #include "eval.hh"
#include "globals.hh" #include "globals.hh"
#include <iostream>
namespace nix { namespace nix {

View file

@ -226,13 +226,14 @@ static void fetch(EvalState & state, const Pos & pos, Value * * args, Value & v,
expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256); expectedHash = newHashAllowEmpty(state.forceStringNoCtx(*attr.value, *attr.pos), htSHA256);
else if (n == "name") else if (n == "name")
name = state.forceStringNoCtx(*attr.value, *attr.pos); name = state.forceStringNoCtx(*attr.value, *attr.pos);
else { else
auto e = EvalError({ {
.msg = hintfmt("unsupported argument '%s' to '%s'", attr.name, who), auto e = EvalError({
.errPos = *attr.pos .msg = hintfmt("unsupported argument '%s' to '%s'", attr.name, who),
}); .errPos = *attr.pos
state.debugLastTrace(e); });
throw e; state.debugLastTrace(e);
throw e;
} }
} }