aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDomen Kožar <domen@dev.si>2020-04-09 09:45:15 +0200
committerDomen Kožar <domen@dev.si>2020-04-09 09:45:15 +0200
commita693a9fa4b92df0d3283a9de8b1e968378a026d2 (patch)
treebb4955e9aa366d4d58794026f9b60ed0725d932e
parent74f94d6640b23d04e6a46a2d0851db6393eebfd6 (diff)
Attach pos to if expression errors
-rw-r--r--src/libexpr/eval.cc2
-rw-r--r--src/libexpr/nixexpr.hh3
-rw-r--r--src/libexpr/parser.y2
3 files changed, 4 insertions, 3 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index b91a021b4..f963a42ca 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -1256,7 +1256,7 @@ void ExprWith::eval(EvalState & state, Env & env, Value & v)
void ExprIf::eval(EvalState & state, Env & env, Value & v)
{
- (state.evalBool(env, cond) ? then : else_)->eval(state, env, v);
+ (state.evalBool(env, cond, pos) ? then : else_)->eval(state, env, v);
}
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh
index 8c96de37c..25798cac6 100644
--- a/src/libexpr/nixexpr.hh
+++ b/src/libexpr/nixexpr.hh
@@ -262,8 +262,9 @@ struct ExprWith : Expr
struct ExprIf : Expr
{
+ Pos pos;
Expr * cond, * then, * else_;
- ExprIf(Expr * cond, Expr * then, Expr * else_) : cond(cond), then(then), else_(else_) { };
+ ExprIf(const Pos & pos, Expr * cond, Expr * then, Expr * else_) : pos(pos), cond(cond), then(then), else_(else_) { };
COMMON_METHODS
};
diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y
index b33ab908b..1993fa6c1 100644
--- a/src/libexpr/parser.y
+++ b/src/libexpr/parser.y
@@ -335,7 +335,7 @@ expr_function
;
expr_if
- : IF expr THEN expr ELSE expr { $$ = new ExprIf($2, $4, $6); }
+ : IF expr THEN expr ELSE expr { $$ = new ExprIf(CUR_POS, $2, $4, $6); }
| expr_op
;