qBraid / pyqasm

Python toolkit providing OpenQASM 3 semantic analyzer and utilities for program analysis and compilation.
https://sdk.qbraid.com/projects/pyqasm
GNU General Public License v3.0
2 stars 1 forks source link

[BUG] `UnboundLocalError` in visitor.py #27

Closed ryanhill1 closed 1 day ago

ryanhill1 commented 3 days ago
$ python3 examples/unroll_example.py
Traceback (most recent call last):
  File ".../pyqasm/examples/unroll_example.py", line 56, in <module>
    print(unroll(example_qasm_program).unrolled_qasm)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pyqasm/pyqasm/unroller.py", line 53, in unroll
    module.accept(visitor)
  File ".../pyqasm/pyqasm/elements.py", line 210, in accept
    self.unrolled_ast.statements.extend(visitor.visit_basic_block(self._statements))
                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pyqasm/pyqasm/visitor.py", line 1549, in visit_basic_block
    result.extend(self.visit_statement(stmt))
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pyqasm/pyqasm/visitor.py", line 1528, in visit_statement
    _, ret_stmts = visitor_function(statement)  # type: ignore[operator]
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pyqasm/pyqasm/visitor.py", line 1519, in <lambda>
    qasm3_ast.ExpressionStatement: lambda x: self._visit_function_call(x.expression),
                                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../pyqasm/pyqasm/visitor.py", line 1314, in _visit_function_call
    return return_value, result
           ^^^^^^^^^^^^
UnboundLocalError: cannot access local variable 'return_value' where it is not associated with a value

https://github.com/qBraid/pyqasm/blob/6237e1c7d432e41005bc00a40896233286071986/pyqasm/visitor.py#L1296-L1314

if not return_statement, return_value is never defined

TheGupta2012 commented 2 days ago

This should be fixed by #21