From b53281d7ec7ba61bd2f78d8df9abce0dd8182dbb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 13 May 2014 11:46:19 +0200
Subject: [PATCH] Forbid model local variables in planner_objective.

Otherwise the preprocessor crashes.

(cherry picked from commit c45f45f58ed144ede58211614101ba763fdbf785)
---
 preprocessor/ParsingDriver.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc
index aa8b3796b..09d81ccf9 100644
--- a/preprocessor/ParsingDriver.cc
+++ b/preprocessor/ParsingDriver.cc
@@ -323,6 +323,9 @@ ParsingDriver::add_model_variable(int symb_id, int lag)
   if (dynamic_cast<StaticModel *>(model_tree) != NULL && lag != 0)
     error("Leads and lags on variables are forbidden in 'planner_objective'.");
 
+  if (dynamic_cast<StaticModel *>(model_tree) != NULL && type == eModelLocalVariable)
+    error("Model local variable " + mod_file->symbol_table.getName(symb_id) + " cannot be used in 'planner_objective'.");
+
   // It makes sense to allow a lead/lag on parameters: during steady state calibration, endogenous and parameters can be swapped
   return model_tree->AddVariable(symb_id, lag);
 }
-- 
GitLab