forceInt: Show position info
This commit is contained in:
parent
c28de6d96e
commit
b62d36963c
3 changed files with 11 additions and 11 deletions
|
@ -1151,11 +1151,11 @@ void EvalState::strictForceValue(Value & v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
NixInt EvalState::forceInt(Value & v)
|
NixInt EvalState::forceInt(Value & v, const Pos & pos)
|
||||||
{
|
{
|
||||||
forceValue(v);
|
forceValue(v);
|
||||||
if (v.type != tInt)
|
if (v.type != tInt)
|
||||||
throwTypeError("value is %1% while an integer was expected", v);
|
throwTypeError("value is %1% while an integer was expected, at %2%", v, pos);
|
||||||
return v.integer;
|
return v.integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -158,7 +158,7 @@ public:
|
||||||
void strictForceValue(Value & v);
|
void strictForceValue(Value & v);
|
||||||
|
|
||||||
/* 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);
|
NixInt forceInt(Value & v, const Pos & pos);
|
||||||
bool forceBool(Value & v);
|
bool forceBool(Value & v);
|
||||||
inline void forceAttrs(Value & v);
|
inline void forceAttrs(Value & v);
|
||||||
inline void forceList(Value & v);
|
inline void forceList(Value & v);
|
||||||
|
|
|
@ -954,7 +954,7 @@ static void elemAt(EvalState & state, const Pos & pos, Value & list, int n, Valu
|
||||||
/* Return the n-1'th element of a list. */
|
/* Return the n-1'th element of a list. */
|
||||||
static void prim_elemAt(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
static void prim_elemAt(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
elemAt(state, pos, *args[0], state.forceInt(*args[1]), v);
|
elemAt(state, pos, *args[0], state.forceInt(*args[1], pos), v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1061,27 +1061,27 @@ static void prim_length(EvalState & state, const Pos & pos, Value * * args, Valu
|
||||||
|
|
||||||
static void prim_add(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
static void prim_add(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
mkInt(v, state.forceInt(*args[0]) + state.forceInt(*args[1]));
|
mkInt(v, state.forceInt(*args[0], pos) + state.forceInt(*args[1], pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void prim_sub(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
static void prim_sub(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
mkInt(v, state.forceInt(*args[0]) - state.forceInt(*args[1]));
|
mkInt(v, state.forceInt(*args[0], pos) - state.forceInt(*args[1], pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void prim_mul(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
static void prim_mul(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
mkInt(v, state.forceInt(*args[0]) * state.forceInt(*args[1]));
|
mkInt(v, state.forceInt(*args[0], pos) * state.forceInt(*args[1], pos));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
static void prim_div(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
NixInt i2 = state.forceInt(*args[1]);
|
NixInt i2 = state.forceInt(*args[1], pos);
|
||||||
if (i2 == 0) throw EvalError(format("division by zero, at %1%") % pos);
|
if (i2 == 0) throw EvalError(format("division by zero, at %1%") % pos);
|
||||||
mkInt(v, state.forceInt(*args[0]) / i2);
|
mkInt(v, state.forceInt(*args[0], pos) / i2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1116,8 +1116,8 @@ static void prim_toString(EvalState & state, const Pos & pos, Value * * args, Va
|
||||||
non-negative. */
|
non-negative. */
|
||||||
static void prim_substring(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
static void prim_substring(EvalState & state, const Pos & pos, Value * * args, Value & v)
|
||||||
{
|
{
|
||||||
int start = state.forceInt(*args[0]);
|
int start = state.forceInt(*args[0], pos);
|
||||||
int len = state.forceInt(*args[1]);
|
int len = state.forceInt(*args[1], pos);
|
||||||
PathSet context;
|
PathSet context;
|
||||||
string s = state.coerceToString(*args[2], context);
|
string s = state.coerceToString(*args[2], context);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue