mirror of
https://github.com/NixOS/nix.git
synced 2025-11-12 21:46:01 +01:00
restore proper handling of no formals vs. 0 formals
e.g. (foo@{}: 1) { a = 3; } should error, but wasn't with the previous
commit
This commit is contained in:
parent
4a80c92a4d
commit
e43888890f
9 changed files with 16 additions and 18 deletions
|
|
@ -1496,13 +1496,13 @@ void EvalState::callFunction(Value & fun, std::span<Value *> args, Value & vRes,
|
|||
|
||||
ExprLambda & lambda(*vCur.lambda().fun);
|
||||
|
||||
auto size = (!lambda.arg ? 0 : 1) + lambda.nFormals;
|
||||
auto size = (!lambda.arg ? 0 : 1) + (lambda.hasFormals ? lambda.getFormals().size() : 0);
|
||||
Env & env2(mem.allocEnv(size));
|
||||
env2.up = vCur.lambda().env;
|
||||
|
||||
Displacement displ = 0;
|
||||
|
||||
if (!lambda.hasFormals())
|
||||
if (!lambda.hasFormals)
|
||||
env2.values[displ++] = args[0];
|
||||
else {
|
||||
try {
|
||||
|
|
@ -1747,7 +1747,7 @@ void EvalState::autoCallFunction(const Bindings & args, Value & fun, Value & res
|
|||
}
|
||||
}
|
||||
|
||||
if (!fun.isLambda() || !fun.lambda().fun->hasFormals()) {
|
||||
if (!fun.isLambda() || !fun.lambda().fun->hasFormals) {
|
||||
res = fun;
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -490,6 +490,7 @@ struct ExprLambda : Expr
|
|||
Symbol arg;
|
||||
|
||||
bool ellipsis;
|
||||
bool hasFormals;
|
||||
uint16_t nFormals;
|
||||
Formal * formalsStart;
|
||||
|
||||
|
|
@ -501,6 +502,7 @@ struct ExprLambda : Expr
|
|||
: pos(pos)
|
||||
, arg(arg)
|
||||
, ellipsis(formals.ellipsis)
|
||||
, hasFormals(true)
|
||||
, nFormals(formals.formals.size())
|
||||
, formalsStart(alloc.allocate_object<Formal>(nFormals))
|
||||
, body(body)
|
||||
|
|
@ -511,7 +513,7 @@ struct ExprLambda : Expr
|
|||
ExprLambda(std::pmr::polymorphic_allocator<char> & alloc, PosIdx pos, Symbol arg, Expr * body)
|
||||
: pos(pos)
|
||||
, arg(arg)
|
||||
, nFormals(0)
|
||||
, hasFormals(false)
|
||||
, formalsStart(nullptr)
|
||||
, body(body) {};
|
||||
|
||||
|
|
@ -529,11 +531,6 @@ struct ExprLambda : Expr
|
|||
void setName(Symbol name) override;
|
||||
std::string showNamePos(const EvalState & state) const;
|
||||
|
||||
inline bool hasFormals() const
|
||||
{
|
||||
return nFormals > 0;
|
||||
}
|
||||
|
||||
std::vector<Formal> getFormalsLexicographic(const SymbolTable & symbols) const
|
||||
{
|
||||
std::vector<Formal> result(getFormals().begin(), getFormals().end());
|
||||
|
|
@ -551,6 +548,7 @@ struct ExprLambda : Expr
|
|||
|
||||
std::span<Formal> getFormals() const
|
||||
{
|
||||
assert(hasFormals);
|
||||
return {formalsStart, nFormals};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ void ExprList::show(const SymbolTable & symbols, std::ostream & str) const
|
|||
void ExprLambda::show(const SymbolTable & symbols, std::ostream & str) const
|
||||
{
|
||||
str << "(";
|
||||
if (hasFormals()) {
|
||||
if (hasFormals) {
|
||||
str << "{ ";
|
||||
bool first = true;
|
||||
// the natural Symbol ordering is by creation time, which can lead to the
|
||||
|
|
@ -451,14 +451,14 @@ void ExprLambda::bindVars(EvalState & es, const std::shared_ptr<const StaticEnv>
|
|||
if (es.debugRepl)
|
||||
es.exprEnvs.insert(std::make_pair(this, env));
|
||||
|
||||
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, nFormals + (!arg ? 0 : 1));
|
||||
auto newEnv = std::make_shared<StaticEnv>(nullptr, env, (hasFormals ? getFormals().size() : 0) + (!arg ? 0 : 1));
|
||||
|
||||
Displacement displ = 0;
|
||||
|
||||
if (arg)
|
||||
newEnv->vars.emplace_back(arg, displ++);
|
||||
|
||||
if (hasFormals()) {
|
||||
if (hasFormals) {
|
||||
for (auto & i : getFormals())
|
||||
newEnv->vars.emplace_back(i.name, displ++);
|
||||
|
||||
|
|
|
|||
|
|
@ -3363,7 +3363,7 @@ static void prim_functionArgs(EvalState & state, const PosIdx pos, Value ** args
|
|||
if (!args[0]->isLambda())
|
||||
state.error<TypeError>("'functionArgs' requires a function").atPos(pos).debugThrow();
|
||||
|
||||
if (!args[0]->lambda().fun->hasFormals()) {
|
||||
if (!args[0]->lambda().fun->hasFormals) {
|
||||
v.mkAttrs(&Bindings::emptyBindings);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,7 +145,7 @@ static void printValueAsXML(
|
|||
posToXML(state, xmlAttrs, state.positions[v.lambda().fun->pos]);
|
||||
XMLOpenElement _(doc, "function", xmlAttrs);
|
||||
|
||||
if (v.lambda().fun->hasFormals()) {
|
||||
if (v.lambda().fun->hasFormals) {
|
||||
XMLAttrs attrs;
|
||||
if (v.lambda().fun->arg)
|
||||
attrs["name"] = state.symbols[v.lambda().fun->arg];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue