🐛 Register-reference validation is incomplete in the parser
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先跟踪 preprocessCode 以及提到的入口点 validateTargets、parseBitRegisterRef 和 parseClassicConditionExpression,使用 definedRegisters 了解现有的量子比特检查。为两个相关路径添加标识符、寄存器存在性、索引边界和 expectedValue 范围验证。完成的标准是拒绝格式错误的引用和不可能的比较,同时列出的范围外情况保持不变。
由索引模型根据 Issue 内容生成。
描述
🤖 AI text below 🤖
Problem statement
The parser has three related gaps in how it validates register references and comparison values:
-
Well-formed identifier checking. Neither
validateTargets(for qubit targets in gate calls) norparseBitRegisterRef(for classical bits inifconditions) rejects malformed register names on lexical grounds. Inputs likec2](dangling]) or@#(not an identifier at all) slip through the shape check. On the qubit side the eventualdefinedRegisterslookup rejects them indirectly with an "unknown register" error; on the classical side there is no lookup, so the error surfaces even later in the DD backend. -
Classical bit reference against declared registers.
validateTargetsverifies that qubit targets exist indefinedRegistersand that the bit index fits within the register size. Nothing analogous runs for the register mentioned in anifcondition:if (nonexistent == 1)andif (c[999] == 1)(withcreg c[3]) both parse without complaint. -
expectedValuewithin the register's representable range.if (c == 999)oncreg c[3](3 bits, values 0 to 7) is impossible to satisfy but the parser accepts it. The comparison always evaluates to false at runtime.
Surfaced during the review of PR #463.
Proposed solution
Add the three missing checks and share them where the same code path applies to qubits and classical bits:
- Extract a small
isValidIdentifierhelper (letter or underscore followed by letters, digits, or underscores). Use it invalidateTargets(before thedefinedRegisterslookup) and inparseBitRegisterRef(before returning the reference). - Extend
preprocessCodeso it also runs an existence + bounds check on the register mentioned in the condition of anif, using the samedefinedRegistersmap already available there. The exact placement (insideparseClassicConditionExpressionor a separatevalidateClassicConditionpass) is an implementation detail. - Reject
expectedValuevalues that exceed what the referenced register can hold (whole register or single bit).
Out of scope
- Reserved-word checking (
qreg,creg,measure, etc.). Separate semantic concern. - Compound expressions in the condition (out of scope of the parser as a whole today).
- 主要语言
- C++
- 星标
- 21
- 派生
- 8
- 平均合并
- 5 小时 17 分钟
- 30 天内合并 PR
- 21
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
munich-quantum-toolkit/debugger 的其他 Issue
-
难度 3/5 1-2 天 新手友好度 84/100
munich-quantum-toolkit/debugger#469 ·
维护者通常 1 天内回复
-
✨ Improve CLI UX: line editing, function-key shortcuts, and help bar可能已有人在做 @rturrado 于 30 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 35/100
munich-quantum-toolkit/debugger#467 ·
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
munich-quantum-toolkit/debugger#465 ·
维护者通常 1 天内回复
-
c++ enhancement help wanted
难度 4/5 3-5 天 新手友好度 48/100
munich-quantum-toolkit/debugger#168 ·
维护者通常 1 天内回复
-
dependencies
难度 5/5 一周以上 新手友好度 10/100
munich-quantum-toolkit/debugger#55 · 1 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
查看 munich-quantum-toolkit/debugger 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
FriendsofECCE/ECCE#336 · 1 条评论 ·
-
error not reported low priority semantics
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
bitcoin-core/gui-qml#1030 ·
维护者通常 3 天内回复
-
难度 2/5 1-3 小时 新手友好度 80/100
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复