Make EvalState::getBuiltin safe for missing attr

This commit is contained in:
Robert Hensing 2024-11-19 17:30:58 +01:00
parent 3b76d01f3b
commit a58e38dab7
2 changed files with 10 additions and 1 deletions

View File

@ -525,7 +525,11 @@ Value * EvalState::addPrimOp(PrimOp && primOp)
Value & EvalState::getBuiltin(const std::string & name)
{
return *baseEnv.values[0]->attrs()->find(symbols.create(name))->value;
auto it = baseEnv.values[0]->attrs()->get(symbols.create(name));
if (it)
return *it->value;
else
throw EvalError("builtin '%1%' not found", name);
}

View File

@ -623,6 +623,11 @@ private:
public:
/**
* Retrieve a specific builtin, equivalent to evaluating `builtins.${name}`.
* @param name The attribute name of the builtin to retrieve.
* @throws EvalError if the builtin does not exist.
*/
Value & getBuiltin(const std::string & name);
struct Doc