Copilot commented on code in PR #12956:
URL: https://github.com/apache/trafficserver/pull/12956#discussion_r2919623783


##########
tools/hrw4u/src/hrw_visitor.py:
##########
@@ -407,10 +395,27 @@ def _close_if_and_section(self) -> None:
     def _ensure_section_open(self, section_label: SectionType) -> None:
         """Ensure a section is open for statements."""
         if not self._section_opened:
+            relocated_lines = None
+            relocated_if_depth = 0
+            if self._if_depth > 0 and self._pre_section_if_start is not None:
+                relocated_lines = self.output[self._pre_section_if_start:]
+                relocated_if_depth = self._if_depth
+                self.output = self.output[:self._pre_section_if_start]
+                self.stmt_indent -= self._if_depth
+                self._if_depth = 0
+                self._pre_section_if_start = None

Review Comment:
   `_pre_section_if_start` is used as an index into `self.output`, but it’s 
only cleared on the relocation path. If an `if` starts while no section is open 
and the block is closed without ever triggering relocation (or the state is 
reset via other transitions), `_pre_section_if_start` can become stale and 
later relocations could slice/move unrelated lines. Consider resetting 
`_pre_section_if_start` alongside other condition/section state (e.g., in 
`_reset_condition_state()` and/or `_close_if_and_section()`), so it can’t 
survive past the lifecycle it’s meant to track.



##########
tools/hrw4u/src/hrw_visitor.py:
##########
@@ -407,10 +395,27 @@ def _close_if_and_section(self) -> None:
     def _ensure_section_open(self, section_label: SectionType) -> None:
         """Ensure a section is open for statements."""
         if not self._section_opened:
+            relocated_lines = None
+            relocated_if_depth = 0
+            if self._if_depth > 0 and self._pre_section_if_start is not None:
+                relocated_lines = self.output[self._pre_section_if_start:]
+                relocated_if_depth = self._if_depth
+                self.output = self.output[:self._pre_section_if_start]
+                self.stmt_indent -= self._if_depth
+                self._if_depth = 0
+                self._pre_section_if_start = None
+
             self.emit(f"{section_label.value} {{")
             self._section_opened = True
             self.increase_indent()
 
+            if relocated_lines:
+                indent_prefix = " " * SystemDefaults.INDENT_SPACES
+                for line in relocated_lines:
+                    self.output.append(indent_prefix + line if line.strip() 
else line)
+                self._if_depth = relocated_if_depth
+                self.stmt_indent += relocated_if_depth

Review Comment:
   Relocated lines are re-indented by manually prefixing a fixed one-level 
space string and appending directly to `self.output`. This bypasses the normal 
emission pathway (`emit`/`emit_line`) and can diverge from any future 
indentation rules (e.g., different indent widths, indentation normalization, 
debug hooks). Consider re-emitting relocated lines via the same helper used 
elsewhere (or centralizing the indentation logic) so all output formatting 
flows through one mechanism.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to