From 5106a0ecfef5b5052e6dd391378179cac9a1a0a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Thu, 13 Mar 2025 17:31:27 +0100
Subject: [PATCH] Improve error message for incorrect complementarity
 conditions

---
 src/ExprNode.cc      | 6 +++---
 src/ParsingDriver.cc | 3 ++-
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/ExprNode.cc b/src/ExprNode.cc
index e7b98e01..6e71fde2 100644
--- a/src/ExprNode.cc
+++ b/src/ExprNode.cc
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2007-2024 Dynare Team
+ * Copyright © 2007-2025 Dynare Team
  *
  * This file is part of Dynare.
  *
@@ -9640,11 +9640,11 @@ BinaryOpNode::matchComplementarityCondition(const optional<int>& heterogeneity_d
             || (!is_greater
                 && (barg1->op_code == BinaryOpcode::less
                     || barg1->op_code == BinaryOpcode::lessEqual)))))
-    throw MatchFailureException {"Complementarity condition does not have the right form"};
+    throw MatchFailureException {};
 
   auto id = match_contemporaneous_endogenous(barg1->arg2);
   if (!id)
-    throw MatchFailureException {"Complementarity condition does not have the right form"};
+    throw MatchFailureException {};
   check_bound_constant(barg1->arg1);
   check_bound_constant(arg2);
 
diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc
index 26a70bc0..abbbf468 100644
--- a/src/ParsingDriver.cc
+++ b/src/ParsingDriver.cc
@@ -2770,7 +2770,8 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2, map<string, string> eq_
       }
     catch (ExprNode::MatchFailureException& e)
       {
-        error("Complementarity condition has an incorrect form: " + e.message);
+        error("Complementarity condition has an incorrect form"s
+              + (e.message.empty() ? ""s : ": "s + e.message));
       }
 
   if (eq_tags.contains("static"))
-- 
GitLab