diff --git a/src/libcmd/installables.cc b/src/libcmd/installables.cc index bce666de5..f85bd4c13 100644 --- a/src/libcmd/installables.cc +++ b/src/libcmd/installables.cc @@ -618,10 +618,10 @@ std::vector> SourceExprCommand::parseInstallables( if (file) state->evalFile(lookupFileArg(*state, *file), *vFile); else { + std::cout << "pre parseExprFromString" << std::endl; auto e = state->parseExprFromString(*expr, absPath(".")); - int x = 5; - std::cout << "x =" << x << std::endl; + std::cout << "pre eval" << std::endl; state->eval(e, *vFile); } diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index 8b883e185..6ca0de72b 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -262,34 +262,52 @@ void ExprVar::bindVars(const std::shared_ptr &env) { /* Check whether the variable appears in the environment. If so, set its level and displacement. */ - const StaticEnv * curEnv; - unsigned int level; - int withLevel = -1; - for (curEnv = env.get(), level = 0; curEnv; curEnv = curEnv->up, level++) { - if (curEnv->isWith) { - if (withLevel == -1) withLevel = level; - } else { - StaticEnv::Vars::const_iterator i = curEnv->vars.find(name); - if (i != curEnv->vars.end()) { - fromWith = false; - this->level = level; - displ = i->second; - return; - } - } + + std::cout << "ExprVar::bindVars " << name << std::endl; + + int a = 10; + if (name == "callPackage") { + a++; // try to make code that I can put a breakpoint on... + std::cout << "meh" << a + 10 << std::endl; + int withLevel = -1; + fromWith = true; + // this->level = withLevel; } - /* Otherwise, the variable must be obtained from the nearest - enclosing `with'. If there is no `with', then we can issue an - "undefined variable" error now. */ - if (withLevel == -1) - std::cout << " throw UndefinedVarError({" << std::endl; - throw UndefinedVarError({ - .msg = hintfmt("undefined variable '%1%'", name), - .errPos = pos - }); - fromWith = true; - this->level = withLevel; + { + + const StaticEnv * curEnv; + unsigned int level; + int withLevel = -1; + for (curEnv = env.get(), level = 0; curEnv; curEnv = curEnv->up, level++) { + if (curEnv->isWith) { + if (withLevel == -1) withLevel = level; + } else { + StaticEnv::Vars::const_iterator i = curEnv->vars.find(name); + if (i != curEnv->vars.end()) { + fromWith = false; + this->level = level; + displ = i->second; + return; + } + } + } + + + /* Otherwise, the variable must be obtained from the nearest + enclosing `with'. If there is no `with', then we can issue an + "undefined variable" error now. */ + if (withLevel == -1) + { + std::cout << " throw UndefinedVarError({" << std::endl; + throw UndefinedVarError({ + .msg = hintfmt("undefined variable (ExprVar bindvars) '%1%'", name), + .errPos = pos + }); + } + fromWith = true; + this->level = withLevel; + } } void ExprSelect::bindVars(const std::shared_ptr &env) @@ -418,6 +436,7 @@ void ExprWith::bindVars(const std::shared_ptr &env) std::cout << "EvalState::parse newEnv " << i->first << std::endl; + std::cout << " body->bindVars(newEnv), iswith: " << newEnv->isWith << std::endl; body->bindVars(newEnv); std::cout << " ExprWith::bindVars 3" << std::endl; }