Unverified Commit 02ee0776 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Fix handling of undeclared variables in the planner_objective statement

Closes: #81
parent 1e4eadb2
......@@ -2269,7 +2269,7 @@ PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct, WarningC
assert(model_tree.equation_number() == 1);
if (model_tree.exoPresentInEqs())
{
cerr << "ERROR: You cannot include exogenous variables in the planner objective. Please "
cerr << "ERROR: You cannot include exogenous variables (or variables of undeclared type) in the planner objective. Please "
<< "define an auxiliary endogenous variable like eps_aux=epsilon and use it instead "
<< "of the varexo." << endl;
exit(EXIT_FAILURE);
......
......@@ -321,8 +321,9 @@ ParsingDriver::add_model_variable(const string &name)
}
catch (SymbolTable::UnknownSymbolNameException &e)
{
// Declare variable as exogenous to continue parsing
// processing will end at end of model block if nostrict option was not passed
/* Declare variable as exogenous to continue parsing. Processing will end
at end of model block (or planner_objective statement) if nostrict
option was not passed. */
declare_exogenous(name);
undeclared_model_vars.insert(name);
symb_id = mod_file->symbol_table.getID(name);
......@@ -785,6 +786,7 @@ ParsingDriver::end_model()
exit_after_write = true;
cerr << it.second << endl;
}
undeclared_model_variable_errors.clear();
if (exit_after_write)
exit(EXIT_FAILURE);
......@@ -2022,6 +2024,21 @@ ParsingDriver::end_planner_objective(expr_t expr)
mod_file->addStatement(make_unique<PlannerObjectiveStatement>(*planner_objective));
// Handle undeclared variables (see #81)
bool exit_after_write = false;
if (undeclared_model_variable_errors.size() > 0)
for (auto &it : undeclared_model_variable_errors)
if (nostrict)
warning(it.second);
else
{
exit_after_write = true;
cerr << it.second << endl;
}
undeclared_model_variable_errors.clear();
if (exit_after_write)
exit(EXIT_FAILURE);
reset_data_tree();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment