Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AssertionError if x is conditionally redefined then used as an index #788

Open
jane-garvin-q opened this issue Jan 31, 2025 · 1 comment

Comments

@jane-garvin-q
Copy link

The attached guppy code causes an AssertionError when evaluated. It seems to be related to the fact that the variable x shadows the x from the library but not on all control flow paths.

@guppy
def main() -> None:
    q = [qubit() for _ in range(1)]
    for i in range(1):
        if i % 2 == 0:
            x = 0
        else:
            for _ in range(1):
                rx(q[x], angle(0.5))
Traceback (most recent call last):
  File "/Users/jane.garvin/Code/eldarion/bug.py", line 35, in <module>
    hugr = guppy.compile_module()
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/decorator.py", line 463, in compile_module
    return module.compile()
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/error.py", line 101, in pretty_errors_wrapped
    return f(*args, **kwargs)
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/module.py", line 346, in compile
    self.check()
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/module.py", line 323, in check
    other_defs = self._check_defs(
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/module.py", line 293, in _check_defs
    return {
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/module.py", line 295, in <dictcomp>
    defn.check(parsed_globals) if isinstance(defn, CheckableDef) else defn
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/definition/function.py", line 106, in check
    cfg = check_global_func_def(self.defined_at, self.ty, globals)
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/checker/func_checker.py", line 80, in check_global_func_def
    return check_cfg(cfg, inputs, ty.output, generic_params, func_def.name, globals)
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/checker/cfg_checker.py", line 108, in check_cfg
    check_rows_match(input_row, compiled[bb].sig.input_row, bb)
  File "/Users/jane.garvin/.venv/lib/python3.10/site-packages/guppylang/checker/cfg_checker.py", line 247, in check_rows_match
    assert map1.keys() == map2.keys()
AssertionError

bug.py.txt

@mark-koch
Copy link
Collaborator

Duplicate of #772

@mark-koch mark-koch marked this as a duplicate of #772 Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants