From 55ae000f993f4fe761811a0de7d006aa4df07828 Mon Sep 17 00:00:00 2001
From: George Marchment <georgemarchment@yahoo.fr>
Date: Wed, 2 Apr 2025 14:34:40 +0200
Subject: [PATCH] Updated tthe rewrite of emits inside a subworkflow

---
 src/subworkflow.py | 31 ++++++++++++++++++++++---------
 1 file changed, 22 insertions(+), 9 deletions(-)

diff --git a/src/subworkflow.py b/src/subworkflow.py
index 713ec15..e8e1a4b 100644
--- a/src/subworkflow.py
+++ b/src/subworkflow.py
@@ -123,17 +123,30 @@ class Subworkflow(Main):
         for e in self.emit:
             if(len(e.gives)==1):
                 ch = e.gives[0]
-                temp = code_after_emit
-                code_after_emit = replace_group1(code_after_emit, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}")
-                if(temp==code_after_emit):
-                    raise Exception("This shoudn't happen -> code hasn't been replaced")
+                if(ch.get_type()=="Channel"):
+                    temp = code_after_emit
+                    code_after_emit = replace_group1(code_after_emit, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}")
+                    if(temp==code_after_emit):
+                        raise Exception("This shoudn't happen -> code hasn't been replaced")
+                elif(ch.get_type()=="Emitted"):
+                    #Case it's an emitted -> we don't change anything -> it is already unique (since the ID has been added to the call)
+                    None
+                else:
+                    raise Exception("This shouldn't happen")
             else:
                 ch = e.origins[0]
-                temp = code_after_emit
-                code_after_emit = replace_group1(code_after_emit, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}")
-                code_up_to_emit+=f"\n{ch.get_code()}_{name} = {ch.get_code()}"
-                if(temp==code_after_emit):
-                    raise Exception("This shoudn't happen -> code hasn't been replaced")
+                if(ch.get_type()=="Channel"):
+                    temp = code_after_emit
+                    code_after_emit = replace_group1(code_after_emit, fr"[^\w]({re.escape(ch.get_code())})[^\w]", f"{ch.get_code()}_{name}")
+                    code_up_to_emit+=f"\n{ch.get_code()}_{name} = {ch.get_code()}"
+                    if(temp==code_after_emit):
+                        raise Exception("This shoudn't happen -> code hasn't been replaced")
+                elif(ch.get_type()=="Emitted"):
+                    #Case it's an emitted -> we don't change anything -> it is already unique (since the ID has been added to the call)
+                    None
+                else:
+                    raise Exception("This shouldn't happen")
+        
 
 
         #In the emits replacing the 'ch = ....' by 'ch' and adding 'ch = ....' at the end of the body
-- 
GitLab