From 1a98a83ef19e79abf25aeac51b800c5ed43b4822 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Tue, 24 Jan 2023 14:11:27 +0100
Subject: [PATCH] =?UTF-8?q?Run=20detrending=20engine=20if=20trend=20variab?=
 =?UTF-8?q?les=20are=20present,=20even=20if=20unused=20in=20a=20var(deflat?=
 =?UTF-8?q?or=3D=E2=80=A6)=20statement?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Closes: #113

(manually cherry picked from commit 1c813a1cf91fecf29f3575f7cf730077ed2a28d0)
---
 src/DynamicModel.cc  | 2 +-
 src/ParsingDriver.cc | 4 ++++
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc
index 8418e8f2..ea98032b 100644
--- a/src/DynamicModel.cc
+++ b/src/DynamicModel.cc
@@ -5150,7 +5150,7 @@ DynamicModel::computeDynJacobianCols(bool jacobianExo)
       int lag = it.first.second;
       int deriv_id = it.second;
       SymbolType type = symbol_table.getType(symb_id);
-      int tsid = symbol_table.getTypeSpecificID(symb_id);
+      int tsid = symbol_table.getTypeSpecificID(symb_id); // At this point, there is no trend_var
 
       switch (type)
         {
diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc
index 8c15fd66..0d6139fe 100644
--- a/src/ParsingDriver.cc
+++ b/src/ParsingDriver.cc
@@ -249,6 +249,10 @@ ParsingDriver::begin_trend()
 void
 ParsingDriver::declare_trend_var(bool log_trend, const string &name, const string &tex_name)
 {
+  /* Run detrending engine if trend variables are present, even if unused in
+     a var(deflator=…) statement (see #113). */
+  mod_file->nonstationary_variables = true;
+
   declare_symbol(name, log_trend ? SymbolType::logTrend : SymbolType::trend, tex_name, {});
   declared_trend_vars.push_back(mod_file->symbol_table.getID(name));
 }
-- 
GitLab