diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index 0ed0c9fb..2da26b57 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -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); diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 04e3541d..bf43e7fc 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -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(*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(); }