diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2020-04-08 15:29:39 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-08 15:29:39 +0200 |
commit | 9ed097db7bc052964e87506527b49715e2ce9ff6 (patch) | |
tree | d88f2a6db23768f68444547761299e0df7e98634 /src | |
parent | 55cefd41d63368d4286568e2956afd535cb44018 (diff) | |
parent | c34e96f7e0d53894f302134b2f90f83b20ffd22a (diff) |
Merge pull request #3468 from Infinisil/functionArgsPositions
Make function arguments retain position info
Diffstat (limited to 'src')
-rw-r--r-- | src/libexpr/nixexpr.hh | 3 | ||||
-rw-r--r-- | src/libexpr/parser.y | 4 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 7 |
3 files changed, 9 insertions, 5 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index f7e9105a4..8c96de37c 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -209,9 +209,10 @@ struct ExprList : Expr struct Formal { + Pos pos; Symbol name; Expr * def; - Formal(const Symbol & name, Expr * def) : name(name), def(def) { }; + Formal(const Pos & pos, const Symbol & name, Expr * def) : pos(pos), name(name), def(def) { }; }; struct Formals diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index a30fb44b5..6f25f5cf0 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -531,8 +531,8 @@ formals ; formal - : ID { $$ = new Formal(data->symbols.create($1), 0); } - | ID '?' expr { $$ = new Formal(data->symbols.create($1), $3); } + : ID { $$ = new Formal(CUR_POS, data->symbols.create($1), 0); } + | ID '?' expr { $$ = new Formal(CUR_POS, data->symbols.create($1), $3); } ; %% diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 629f3da15..d86ceb0e3 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1353,9 +1353,12 @@ static void prim_functionArgs(EvalState & state, const Pos & pos, Value * * args } state.mkAttrs(v, args[0]->lambda.fun->formals->formals.size()); - for (auto & i : args[0]->lambda.fun->formals->formals) + for (auto & i : args[0]->lambda.fun->formals->formals) { // !!! should optimise booleans (allocate only once) - mkBool(*state.allocAttr(v, i.name), i.def); + Value * value = state.allocValue(); + v.attrs->push_back(Attr(i.name, value, &i.pos)); + mkBool(*value, i.def); + } v.attrs->sort(); } |