forceBool(): Show position info

This commit is contained in:
Eelco Dolstra 2016-08-29 17:56:35 +02:00
parent 26d92017d3
commit c42d1acfeb
4 changed files with 14 additions and 13 deletions

View file

@ -1378,11 +1378,11 @@ NixFloat EvalState::forceFloat(Value & v, const Pos & pos)
} }
bool EvalState::forceBool(Value & v) bool EvalState::forceBool(Value & v, const Pos & pos)
{ {
forceValue(v); forceValue(v);
if (v.type != tBool) if (v.type != tBool)
throwTypeError("value is %1% while a Boolean was expected", v); throwTypeError("value is %1% while a Boolean was expected, at %2%", v, pos);
return v.boolean; return v.boolean;
} }

View file

@ -157,7 +157,7 @@ public:
/* Force `v', and then verify that it has the expected type. */ /* Force `v', and then verify that it has the expected type. */
NixInt forceInt(Value & v, const Pos & pos); NixInt forceInt(Value & v, const Pos & pos);
NixFloat forceFloat(Value & v, const Pos & pos); NixFloat forceFloat(Value & v, const Pos & pos);
bool forceBool(Value & v); bool forceBool(Value & v, const Pos & pos);
inline void forceAttrs(Value & v); inline void forceAttrs(Value & v);
inline void forceAttrs(Value & v, const Pos & pos); inline void forceAttrs(Value & v, const Pos & pos);
inline void forceList(Value & v); inline void forceList(Value & v);

View file

@ -301,7 +301,7 @@ static void getDerivations(EvalState & state, Value & vIn,
`recurseForDerivations = true' attribute. */ `recurseForDerivations = true' attribute. */
if (v2.type == tAttrs) { if (v2.type == tAttrs) {
Bindings::iterator j = v2.attrs->find(state.symbols.create("recurseForDerivations")); Bindings::iterator j = v2.attrs->find(state.symbols.create("recurseForDerivations"));
if (j != v2.attrs->end() && state.forceBool(*j->value)) if (j != v2.attrs->end() && state.forceBool(*j->value, *j->pos))
getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures); getDerivations(state, v2, pathPrefix2, autoArgs, drvs, done, ignoreAssertionFailures);
} }
} }

View file

@ -477,7 +477,7 @@ static void prim_derivationStrict(EvalState & state, const Pos & pos, Value * *
bool ignoreNulls = false; bool ignoreNulls = false;
attr = args[0]->attrs->find(state.sIgnoreNulls); attr = args[0]->attrs->find(state.sIgnoreNulls);
if (attr != args[0]->attrs->end()) if (attr != args[0]->attrs->end())
ignoreNulls = state.forceBool(*attr->value); ignoreNulls = state.forceBool(*attr->value, pos);
/* Build the derivation expression by processing the attributes. */ /* Build the derivation expression by processing the attributes. */
Derivation drv; Derivation drv;
@ -925,9 +925,10 @@ struct FilterFromExpr : PathFilter
{ {
EvalState & state; EvalState & state;
Value & filter; Value & filter;
Pos pos;
FilterFromExpr(EvalState & state, Value & filter) FilterFromExpr(EvalState & state, Value & filter, const Pos & pos)
: state(state), filter(filter) : state(state), filter(filter), pos(pos)
{ {
} }
@ -955,7 +956,7 @@ struct FilterFromExpr : PathFilter
Value res; Value res;
state.callFunction(fun2, arg2, res, noPos); state.callFunction(fun2, arg2, res, noPos);
return state.forceBool(res); return state.forceBool(res, pos);
} }
}; };
@ -971,7 +972,7 @@ static void prim_filterSource(EvalState & state, const Pos & pos, Value * * args
if (args[0]->type != tLambda) if (args[0]->type != tLambda)
throw TypeError(format("first argument in call to filterSource is not a function but %1%, at %2%") % showType(*args[0]) % pos); throw TypeError(format("first argument in call to filterSource is not a function but %1%, at %2%") % showType(*args[0]) % pos);
FilterFromExpr filter(state, *args[0]); FilterFromExpr filter(state, *args[0], pos);
path = state.checkSourcePath(path); path = state.checkSourcePath(path);
@ -1291,7 +1292,7 @@ static void prim_filter(EvalState & state, const Pos & pos, Value * * args, Valu
for (unsigned int n = 0; n < args[1]->listSize(); ++n) { for (unsigned int n = 0; n < args[1]->listSize(); ++n) {
Value res; Value res;
state.callFunction(*args[0], *args[1]->listElems()[n], res, noPos); state.callFunction(*args[0], *args[1]->listElems()[n], res, noPos);
if (state.forceBool(res)) if (state.forceBool(res, pos))
vs[k++] = args[1]->listElems()[n]; vs[k++] = args[1]->listElems()[n];
else else
same = false; same = false;
@ -1367,7 +1368,7 @@ static void anyOrAll(bool any, EvalState & state, const Pos & pos, Value * * arg
Value vTmp; Value vTmp;
for (unsigned int n = 0; n < args[1]->listSize(); ++n) { for (unsigned int n = 0; n < args[1]->listSize(); ++n) {
state.callFunction(*args[0], *args[1]->listElems()[n], vTmp, pos); state.callFunction(*args[0], *args[1]->listElems()[n], vTmp, pos);
bool res = state.forceBool(vTmp); bool res = state.forceBool(vTmp, pos);
if (res == any) { if (res == any) {
mkBool(v, any); mkBool(v, any);
return; return;
@ -1433,7 +1434,7 @@ static void prim_sort(EvalState & state, const Pos & pos, Value * * args, Value
Value vTmp1, vTmp2; Value vTmp1, vTmp2;
state.callFunction(*args[0], *a, vTmp1, pos); state.callFunction(*args[0], *a, vTmp1, pos);
state.callFunction(vTmp1, *b, vTmp2, pos); state.callFunction(vTmp1, *b, vTmp2, pos);
return state.forceBool(vTmp2); return state.forceBool(vTmp2, pos);
}; };
/* FIXME: std::sort can segfault if the comparator is not a strict /* FIXME: std::sort can segfault if the comparator is not a strict
@ -1457,7 +1458,7 @@ static void prim_partition(EvalState & state, const Pos & pos, Value * * args, V
state.forceValue(*vElem); state.forceValue(*vElem);
Value res; Value res;
state.callFunction(*args[0], *vElem, res, pos); state.callFunction(*args[0], *vElem, res, pos);
if (state.forceBool(res)) if (state.forceBool(res, pos))
right.push_back(vElem); right.push_back(vElem);
else else
wrong.push_back(vElem); wrong.push_back(vElem);