OpenQASM: Fix const propagation in bitarray-to-int promotion#3030
Merged
minestarks merged 1 commit intomainfrom Mar 23, 2026
Merged
OpenQASM: Fix const propagation in bitarray-to-int promotion#3030minestarks merged 1 commit intomainfrom
minestarks merged 1 commit intomainfrom
Conversation
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.
orpuente-MS
approved these changes
Mar 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_intdetermines the result type when a binary operation involves anint/uintand abit[N]. It used.clone()on whichever operand was already an integer type, which blindly inherited that operand's const qualifier. This meant an expression likeconst int + bit[4]would produceconst intinstead ofint— the non-constbit[4]operand was ignored for constness.