diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-22T11·02+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2010-04-22T11·02+0000 |
commit | ebade9ff8b8557bdae7cdaf9f70c12ceeb3dc02c (patch) | |
tree | 32a2ea8441ed340fd2a0b3b8ab29f5e51950480f /src/libexpr/nixexpr.hh | |
parent | 2d7636529f782b552b634497fd8ac876aae72fcc (diff) |
* Check for duplicate attribute names / function arguments. `make
check' now succeeds :-) * An attribute set such as `{ foo = { enable = true; }; foo.port = 23; }' now parses. It was previously rejected, but I'm too lazy to implement the check. (The only reason to reject it is that the reverse, `{ foo.port = 23; foo = { enable = true; }; }', is rejected, which is kind of ugly.)
Diffstat (limited to 'src/libexpr/nixexpr.hh')
-rw-r--r-- | src/libexpr/nixexpr.hh | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 9e5a262d7f46..4da77ee5861a 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -128,6 +128,7 @@ struct ExprAttrs : Expr typedef std::map<Symbol, Expr *> Attrs; Attrs attrs; list<VarRef> inherited; + set<Symbol> attrNames; // used during parsing ExprAttrs() : recursive(false) { }; COMMON_METHODS }; @@ -150,6 +151,7 @@ struct Formals { typedef std::list<Formal> Formals_; Formals_ formals; + std::set<Symbol> argNames; // used during parsing bool ellipsis; }; @@ -161,7 +163,12 @@ struct ExprLambda : Expr Formals * formals; Expr * body; ExprLambda(const Pos & pos, const Symbol & arg, bool matchAttrs, Formals * formals, Expr * body) - : pos(pos), arg(arg), matchAttrs(matchAttrs), formals(formals), body(body) { }; + : pos(pos), arg(arg), matchAttrs(matchAttrs), formals(formals), body(body) + { + if (!arg.empty() && formals && formals->argNames.find(arg) != formals->argNames.end()) + throw ParseError(format("duplicate formal function argument `%1%' at %2%") + % arg % pos); + }; COMMON_METHODS }; |