Skip to content

OpenQASM: Fix const propagation in bitarray-to-int promotion#3030

Merged
minestarks merged 1 commit intomainfrom
minestarks/lowerer-fix-as-well
Mar 23, 2026
Merged

OpenQASM: Fix const propagation in bitarray-to-int promotion#3030
minestarks merged 1 commit intomainfrom
minestarks/lowerer-fix-as-well

Conversation

@minestarks
Copy link
Copy Markdown
Member

@minestarks minestarks commented Mar 19, 2026

This is a bug we discovered while working on #2990 . It doesn't have any user-visible effects (since constness is ignored when transpiling to Q#), but it impacts the corectness of the internal OpenQASM AST.

try_promote_bitarray_to_int determines the result type when a binary operation involves an int/uint and a bit[N]. It used .clone() on whichever operand was already an integer type, which blindly inherited that operand's const qualifier. This meant an expression like const int + bit[4] would produce const int instead of int — the non-const bit[4] operand was ignored for constness.

The `try_promote_bitarray_to_int` function used `.clone()` on the
matching operand type, which blindly inherited that operand's const
qualifier. When a const int was combined with a non-const bit array
(e.g. `const int + bit[4]`), the result was incorrectly typed as
`const int`.

Add `Type::with_const()` to set the const qualifier on any type, and
use it to compute the correct constness as the conjunction of both
operands' constness.
@minestarks minestarks requested a review from orpuente-MS March 19, 2026 17:59
@minestarks minestarks marked this pull request as ready for review March 19, 2026 18:01
@minestarks minestarks added this pull request to the merge queue Mar 23, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 23, 2026
@minestarks minestarks added this pull request to the merge queue Mar 23, 2026
Merged via the queue into main with commit 766b710 Mar 23, 2026
13 checks passed
@minestarks minestarks deleted the minestarks/lowerer-fix-as-well branch March 23, 2026 20:48
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.

2 participants