From c7f5b022ffe1dd1bbcc47d9303c12c8218448a62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20P=C5=99evr=C3=A1til?= Date: Wed, 13 Mar 2024 09:43:58 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20`is=5Freachable`=20in=20CF?= =?UTF-8?q?G?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wake/analysis/cfg.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/wake/analysis/cfg.py b/wake/analysis/cfg.py index 2221cd67b..80190d797 100644 --- a/wake/analysis/cfg.py +++ b/wake/analysis/cfg.py @@ -254,8 +254,17 @@ def is_reachable( start_node = self._statements_lookup[start] end_node = self._statements_lookup[end] if start_node == end_node: + if start == start_node.control_statement: + if end == start_node.control_statement: + return True + try: + nx.find_cycle(self._graph, start_node) + return True + except nx.NetworkXNoCycle: + return False if end == end_node.control_statement: return True + start_index = start_node.statements.index(start) end_index = end_node.statements.index(end) if start_index <= end_index: # also EQUAL? @@ -605,12 +614,17 @@ def process_expression(expression: ExpressionAbc, node: CfgNode) -> bool: return True else: return False + else: + return False prev._statements.append(statement) next = CfgNode() graph.add_node(next) - if process_expression(statement.expression, prev): + if process_expression( + statement.expression, # pyright: ignore reportArgumentType + prev, + ): return next else: graph.remove_node(next)