Show position info in attribute selection errors

This commit is contained in:
Eelco Dolstra 2014-04-04 22:52:14 +02:00
parent 4c5faad994
commit 8e5fbf4d73
3 changed files with 14 additions and 13 deletions

View file

@ -736,7 +736,7 @@ unsigned long nrLookups = 0;
void ExprSelect::eval(EvalState & state, Env & env, Value & v) void ExprSelect::eval(EvalState & state, Env & env, Value & v)
{ {
Value vTmp; Value vTmp;
Pos * pos = 0; Pos * pos2 = 0;
Value * vAttrs = &vTmp; Value * vAttrs = &vTmp;
e->eval(state, env, vTmp); e->eval(state, env, vTmp);
@ -756,21 +756,21 @@ void ExprSelect::eval(EvalState & state, Env & env, Value & v)
return; return;
} }
} else { } else {
state.forceAttrs(*vAttrs); state.forceAttrs(*vAttrs, pos);
if ((j = vAttrs->attrs->find(name)) == vAttrs->attrs->end()) if ((j = vAttrs->attrs->find(name)) == vAttrs->attrs->end())
throwEvalError("attribute `%1%' missing", showAttrPath(attrPath)); throwEvalError("attribute `%1%' missing, at %2%", showAttrPath(attrPath), pos);
} }
vAttrs = j->value; vAttrs = j->value;
pos = j->pos; pos2 = j->pos;
if (state.countCalls && pos) state.attrSelects[*pos]++; if (state.countCalls && pos2) state.attrSelects[*pos2]++;
} }
state.forceValue(*vAttrs); state.forceValue(*vAttrs);
} catch (Error & e) { } catch (Error & e) {
if (pos && pos->file != state.sDerivationNix) if (pos2 && pos2->file != state.sDerivationNix)
addErrorPrefix(e, "while evaluating the attribute `%1%' at %2%:\n", addErrorPrefix(e, "while evaluating the attribute `%1%' at %2%:\n",
showAttrPath(attrPath), *pos); showAttrPath(attrPath), *pos2);
throw; throw;
} }

View file

@ -149,10 +149,11 @@ struct ExprVar : Expr
struct ExprSelect : Expr struct ExprSelect : Expr
{ {
Pos pos;
Expr * e, * def; Expr * e, * def;
AttrPath attrPath; AttrPath attrPath;
ExprSelect(Expr * e, const AttrPath & attrPath, Expr * def) : e(e), def(def), attrPath(attrPath) { }; ExprSelect(const Pos & pos, Expr * e, const AttrPath & attrPath, Expr * def) : pos(pos), e(e), def(def), attrPath(attrPath) { };
ExprSelect(Expr * e, const Symbol & name) : e(e), def(0) { attrPath.push_back(AttrName(name)); }; ExprSelect(const Pos & pos, Expr * e, const Symbol & name) : pos(pos), e(e), def(0) { attrPath.push_back(AttrName(name)); };
COMMON_METHODS COMMON_METHODS
}; };

View file

@ -361,9 +361,9 @@ expr_app
expr_select expr_select
: expr_simple '.' attrpath : expr_simple '.' attrpath
{ $$ = new ExprSelect($1, *$3, 0); } { $$ = new ExprSelect(CUR_POS, $1, *$3, 0); }
| expr_simple '.' attrpath OR_KW expr_select | expr_simple '.' attrpath OR_KW expr_select
{ $$ = new ExprSelect($1, *$3, $5); } { $$ = new ExprSelect(CUR_POS, $1, *$3, $5); }
| /* Backwards compatibility: because Nixpkgs has a rarely used | /* Backwards compatibility: because Nixpkgs has a rarely used
function named or, allow stuff like map or [...]. */ function named or, allow stuff like map or [...]. */
expr_simple OR_KW expr_simple OR_KW
@ -403,7 +403,7 @@ expr_simple
/* Let expressions `let {..., body = ...}' are just desugared /* Let expressions `let {..., body = ...}' are just desugared
into `(rec {..., body = ...}).body'. */ into `(rec {..., body = ...}).body'. */
| LET '{' binds '}' | LET '{' binds '}'
{ $3->recursive = true; $$ = new ExprSelect($3, data->symbols.create("body")); } { $3->recursive = true; $$ = new ExprSelect(noPos, $3, data->symbols.create("body")); }
| REC '{' binds '}' | REC '{' binds '}'
{ $3->recursive = true; $$ = $3; } { $3->recursive = true; $$ = $3; }
| '{' binds '}' | '{' binds '}'
@ -458,7 +458,7 @@ binds
foreach (AttrPath::iterator, i, *$6) { foreach (AttrPath::iterator, i, *$6) {
if ($$->attrs.find(i->symbol) != $$->attrs.end()) if ($$->attrs.find(i->symbol) != $$->attrs.end())
dupAttr(i->symbol, makeCurPos(@6, data), $$->attrs[i->symbol].pos); dupAttr(i->symbol, makeCurPos(@6, data), $$->attrs[i->symbol].pos);
$$->attrs[i->symbol] = ExprAttrs::AttrDef(new ExprSelect($4, i->symbol), makeCurPos(@6, data)); $$->attrs[i->symbol] = ExprAttrs::AttrDef(new ExprSelect(CUR_POS, $4, i->symbol), makeCurPos(@6, data));
} }
} }
| { $$ = new ExprAttrs; } | { $$ = new ExprAttrs; }