Skip to content

fix: scope variables declared in classical if/else blocks - #442

Open
KainanP wants to merge 1 commit into
amazon-braket:mainfrom
KainanP:fix-branch-block-scope
Open

KainanP wants to merge 1 commit into
amazon-braket:mainfrom
KainanP:fix-branch-block-scope

Conversation

@KainanP

@KainanP KainanP commented Nov 30, 2026

Copy link
Copy Markdown

Issue #, if available: #438

Description of changes:
A classically evaluated if/else ran its block in the enclosing scope, so int v = 0; inside the block overwrote an outer v. The block now runs in its own scope, as for-loop bodies already do.

Testing done:
New test_branch_block_variable_shadowing fails on main (v ends as 5) and passes with the fix; the issue's program now always measures 1. Full test/unit_tests passes (2174 passed, 71 xfailed); ruff check src clean.

Not covered: a classical if evaluated after mid-circuit branching stores variables per path, and shadowing there still replaces the outer value.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

AI-assisted (Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@KainanP
KainanP requested a review from a team as a code owner November 30, 2026 16:12

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

1 participant