From c847a3e759331f2a907a9953194b0dc0f8ab64eb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr>
Date: Thu, 16 Sep 2010 15:37:09 +0200
Subject: [PATCH] Preprocessor: fix crash when mean or stderr of an estimated
 parameter is specified as an expression instead of a plain value (bug
 introduced in 28d30d9a626a8d7be0866038924bfc52a935ee27) (manually
 cherry-picked from c3608b9ba72afa7b88546187d166da881feb2239)

---
 preprocessor/ComputingTasks.cc | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc
index 15e64755a7..39041e43c8 100644
--- a/preprocessor/ComputingTasks.cc
+++ b/preprocessor/ComputingTasks.cc
@@ -320,12 +320,20 @@ EstimatedParamsStatement::EstimatedParamsStatement(const vector<EstimationParams
 {
   for (vector<EstimationParams>::const_iterator it = estim_params_list.begin();
        it != estim_params_list.end(); it++)
+    // Handle case of degenerate beta prior
     if (it->prior == "1") //BETA_PDF is associated with "1" in DynareBison.yy
-      if (dynamic_cast<NumConstNode *>(it->mean)->isNumConstNodeEqualTo(0.5) &&
-          dynamic_cast<NumConstNode *>(it->std)->isNumConstNodeEqualTo(0.5))
+      try
         {
-          cerr << "The prior density is not defined for the beta distribution when the mean = standard deviation = 0.5." << endl;
-          exit(EXIT_FAILURE);
+          if (it->mean->eval(eval_context_type()) == 0.5 &&
+              it->std->eval(eval_context_type()) == 0.5)
+            {
+              cerr << "ERROR: The prior density is not defined for the beta distribution when the mean = standard deviation = 0.5." << endl;
+              exit(EXIT_FAILURE);
+            }
+        }
+      catch (ExprNode::EvalException &e)
+        {
+          // We don't have enough information to compute the numerical value, skip the test
         }
 }
 
-- 
GitLab