1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-25 23:11:16 +02:00

* 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.)
This commit is contained in:
Eelco Dolstra 2010-04-22 11:02:24 +00:00
parent 2d7636529f
commit ebade9ff8b
5 changed files with 58 additions and 45 deletions

View file

@ -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
};