From dbe14ecfd4bb04ea24880e7715e855332f8b1a8d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 26 Apr 2022 11:45:22 +0200
Subject: [PATCH] =?UTF-8?q?Add=20checks=20on=20the=20value=20of=20the=20?=
 =?UTF-8?q?=E2=80=9Clearnt=5Fin=E2=80=9D=20option=20of=20=E2=80=9Cshocks?=
 =?UTF-8?q?=E2=80=9D=20and=20=E2=80=9Cendval=E2=80=9D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 src/ParsingDriver.cc | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc
index 221ab487..806a4642 100644
--- a/src/ParsingDriver.cc
+++ b/src/ParsingDriver.cc
@@ -750,10 +750,13 @@ ParsingDriver::end_endval(bool all_values_required)
 void
 ParsingDriver::end_endval_learnt_in(const string &learnt_in_period)
 {
+  int learnt_in_period_int = stoi(learnt_in_period);
+  if (learnt_in_period_int < 2)
+    error("endval: value '" + learnt_in_period + "' is not allowed for 'learnt_in' option");
   for (auto [symb_id, value] : init_values)
     if (mod_file->symbol_table.getType(symb_id) != SymbolType::exogenous)
       error("endval(learnt_in=...): " + mod_file->symbol_table.getName(symb_id) + " is not an exogenous variable");
-  mod_file->addStatement(make_unique<EndValLearntInStatement>(stoi(learnt_in_period), init_values, mod_file->symbol_table));
+  mod_file->addStatement(make_unique<EndValLearntInStatement>(learnt_in_period_int, init_values, mod_file->symbol_table));
   init_values.clear();
 }
 
@@ -862,6 +865,8 @@ void
 ParsingDriver::end_shocks_learnt_in(const string &learnt_in_period, bool overwrite)
 {
   int learnt_in_period_int = stoi(learnt_in_period);
+  if (learnt_in_period_int < 2)
+    error("shocks: value '" + learnt_in_period + "' is not allowed for 'learnt_in' option");
   for (auto &[symb_id, vals] : det_shocks)
     for (auto [period1, period2, expr] : vals)
       if (period1 < learnt_in_period_int)
-- 
GitLab