From 045a1f00363b524121476cb56c5a7b4f44b63d7e Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Thu, 10 Feb 2022 22:10:26 +0100
Subject: [PATCH] FIX: Fix option/function/job add for IrModule

---
 src/Lib/Script/Ast/IrModule.cc | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/Lib/Script/Ast/IrModule.cc b/src/Lib/Script/Ast/IrModule.cc
index dbeb2efd..dfcfe6ef 100644
--- a/src/Lib/Script/Ast/IrModule.cc
+++ b/src/Lib/Script/Ast/IrModule.cc
@@ -120,16 +120,19 @@ IrModule::addImport(IrImport *importStatement)
 void
 IrModule::addOption(IrOption *obj)
 {
-    if (option(obj->name()) != nullptr)
+    if (option(obj->name()) == nullptr) {
         localOptions.push_back(obj);
-    else
-        throw std::runtime_error("Can't add multiple times an option with the same name");
+    } else {
+        throw std::runtime_error("Can't add multiple times an option with the same name, "
+                                 "duplicate name is: " +
+                                 obj->name().toStdString());
+    }
 }
 
 void
 IrModule::addFunction(IrFunction *obj)
 {
-    if (function(obj->name()) != nullptr)
+    if (function(obj->name()) == nullptr)
         localFunctions.push_back(obj);
     else
         throw std::runtime_error("Can't add multiple times an function with the same name");
@@ -138,7 +141,7 @@ IrModule::addFunction(IrFunction *obj)
 void
 IrModule::addJob(IrJob *obj)
 {
-    if (job(obj->name()) != nullptr)
+    if (job(obj->name()) == nullptr)
         localJobs.push_back(obj);
     else
         throw std::runtime_error("Can't add multiple times an job with the same name");
-- 
GitLab