forked from lix-project/lix
Treat undefined variable errors consistently
Previously, a undefined variable inside a "with" caused an EvalError (which can be caught), while outside, it caused a ParseError (which cannot be caught). Now both cause an UndefinedVarError (which cannot be caught).
This commit is contained in:
parent
6b47de580f
commit
b1e3b1a4ac
|
@ -258,6 +258,11 @@ LocalNoInlineNoReturn(void throwAssertionError(const char * s, const Pos & pos))
|
||||||
throw AssertionError(format(s) % pos);
|
throw AssertionError(format(s) % pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
LocalNoInlineNoReturn(void throwUndefinedVarError(const char * s, const string & s1, const Pos & pos))
|
||||||
|
{
|
||||||
|
throw UndefinedVarError(format(s) % s1 % pos);
|
||||||
|
}
|
||||||
|
|
||||||
LocalNoInline(void addErrorPrefix(Error & e, const char * s, const string & s2))
|
LocalNoInline(void addErrorPrefix(Error & e, const char * s, const string & s2))
|
||||||
{
|
{
|
||||||
e.addPrefix(format(s) % s2);
|
e.addPrefix(format(s) % s2);
|
||||||
|
@ -315,7 +320,7 @@ inline Value * EvalState::lookupVar(Env * env, const ExprVar & var, bool noEval)
|
||||||
return j->value;
|
return j->value;
|
||||||
}
|
}
|
||||||
if (!env->prevWith)
|
if (!env->prevWith)
|
||||||
throw EvalError(format("undefined variable `%1%' at %2%") % var.name % var.pos);
|
throwUndefinedVarError("undefined variable `%1%' at %2%", var.name, var.pos);
|
||||||
for (unsigned int l = env->prevWith; l; --l, env = env->up) ;
|
for (unsigned int l = env->prevWith; l; --l, env = env->up) ;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ void ExprVar::bindVars(const StaticEnv & env)
|
||||||
/* Otherwise, the variable must be obtained from the nearest
|
/* Otherwise, the variable must be obtained from the nearest
|
||||||
enclosing `with'. If there is no `with', then we can issue an
|
enclosing `with'. If there is no `with', then we can issue an
|
||||||
"undefined variable" error now. */
|
"undefined variable" error now. */
|
||||||
if (withLevel == -1) throw ParseError(format("undefined variable `%1%' at %2%") % name % pos);
|
if (withLevel == -1) throw UndefinedVarError(format("undefined variable `%1%' at %2%") % name % pos);
|
||||||
|
|
||||||
fromWith = true;
|
fromWith = true;
|
||||||
this->level = withLevel;
|
this->level = withLevel;
|
||||||
|
|
|
@ -16,6 +16,7 @@ MakeError(ThrownError, AssertionError)
|
||||||
MakeError(Abort, EvalError)
|
MakeError(Abort, EvalError)
|
||||||
MakeError(TypeError, EvalError)
|
MakeError(TypeError, EvalError)
|
||||||
MakeError(ImportError, EvalError) // error building an imported derivation
|
MakeError(ImportError, EvalError) // error building an imported derivation
|
||||||
|
MakeError(UndefinedVarError, Error)
|
||||||
|
|
||||||
|
|
||||||
/* Position objects. */
|
/* Position objects. */
|
||||||
|
|
Loading…
Reference in a new issue