[Stim] Comment-only line before a REPEAT block's closing brace fails to parse
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
Research direction
The parser lives in source/compiler/stim_compiler/src/parser.rs, and the issue points at parse_block, which checks for Close(Brace) before skipping newlines. Reproduce with the Python snippet in the issue, which should fail with ExpectedToken on close(brace). Done when that snippet compiles and the comment-only line before the closing brace is accepted inside a REPEAT block.
Written by the indexing model from the issue text.
Description
Describe the bug
qdk.stim fails to parse a REPEAT block when a comment-only line comes directly before the closing }. Stim accepts this program. A comment at the end of an instruction line (H 0 # comment) works, and so does a comment-only line elsewhere in the block.
To Reproduce
import sys
import qdk.stim
src = """R 0
REPEAT 2 {
H 0
# comment
}
M 0
"""
try:
qdk.stim.compile(src)
except Exception as e:
print(e)
print("REPRODUCED")
sys.exit(1)
print("NOT REPRODUCED")
This fails with Qdk.Stim.Parser.ExpectedToken: expected instruction_name, found close(brace), followed by UnexpectedEof.
Expected behavior
The program compiles, as it does in Stim (stim.Circuit(src) accepts it).
Additional context
The likely cause is in source/compiler/stim_compiler/src/parser.rs. The lexer skips the comment and then emits another Newline token. parse_block checks for Close(Brace) before skipping newlines, so it calls parse_item, which skips the newline, finds } and fails. Skipping newlines in parse_block before the Close(Brace) check should fix it.
Found by differential fuzzing against Stim 1.16.0.
- Dominant language
- Rust
- Stars
- 1k
- Forks
- 226
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 72
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from microsoft/qdk
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
Maintainers usually reply within 1 day
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug low-priority
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
microsoft/qdk#4187 · 1 comment ·
Maintainers usually reply within 1 day
-
bug bulk-filed needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
libracoder/kiri#935 ·
Maintainers usually reply within 1 day
-
Node's `index.d.ts` declares no constructor for `VirtxError`, so TypeScript rejects its argumentsOpen
Difficulty 1/5 Under an hour Newbie friendliness 88/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kashsuks/Pinel#172 · 1 comment ·
Maintainers usually reply within 1 day