[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM
メンテナーはふだん 1 日以内に返信
評価
調査の方向性
The extern call is appended unwrapped in _handle_extern_function_cleanup in src/pyqasm/visitor.py (around line 591), so start there and check where the extern statement list is assembled. Reproduce with the snippet in the issue and inspect [type(s).__name__ for s in m.unrolled_ast.statements]. Done means the call is wrapped in qasm3_ast.ExpressionStatement and openqasm3.parse(pyqasm.dumps(m)) succeeds for the extern fixtures. Note that PR #450 is open against this issue and #446 was closed unmerged, so check with maintainers before starting.
索引モデルが issue の本文から書いたものです。
説明
Environment
- pyqasm version: 1.2.0 (
main@ 036ad4d) - Python version: 3.12
- Operating system: macOS 15
What happened?
dumps() emits an extern function call without its terminating semicolon, so the generated
program is not valid OpenQASM and will not reparse.
import openqasm3, pyqasm
m = pyqasm.loads("""OPENQASM 3.0;
extern my_extern(int);
my_extern(3);
""")
m.unroll()
out = pyqasm.dumps(m)
print(out)
openqasm3.parse(out)
OPENQASM 3.0;
extern my_extern(int);
my_extern(3)
openqasm3.parser.QASM3ParsingError
With any statement following the call, the two run together on one line:
qubit[1] q;
my_extern(3)x q[0]; # line 5:12 no viable alternative at input 'my_extern(3)'
The cause is the node type, not the printer. The unrolled AST holds a bare FunctionCall
where a statement belongs:
>>> [type(s).__name__ for s in m.unrolled_ast.statements]
['ExternDeclaration', 'FunctionCall']
FunctionCall is an expression node, so openqasm3.printer renders it as an expression —
no semicolon, no line break. It should be wrapped in an ExpressionStatement.
Scope is narrow: only extern calls are affected. Subroutine calls and builtin calls both
round-trip correctly.
extern call QASM3ParsingError tail: ['qubit[1] q;', 'my_extern(3)x q[0];']
extern, no follow QASM3ParsingError tail: ['qubit[1] q;', 'my_extern(3)']
subroutine call reparses OK tail: ['x q[0];', 'x q[0];']
builtin call reparses OK tail: ['qubit[1] q;', 'x q[0];']
Suggestions (Optional)
Wrap the call in qasm3_ast.ExpressionStatement before it is appended to the output
statements — _handle_extern_function_cleanup (src/pyqasm/visitor.py:591) is where the
extern statement list is assembled.
Worth a round-trip assertion in the tests either way: openqasm3.parse(pyqasm.dumps(m)) over
the existing extern fixtures would have caught this, and would catch the same class of bug for
any other node that reaches the statement list unwrapped.
Found while reviewing #425, which touches the expression-statement path but does not cause or
fix this — it reproduces identically on main.
- 主要言語
- Python
- スター
- 29
- フォーク
- 33
- 平均マージ
- 2日 4時間
- マージ済み PR(30日)
- 15
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
qBraid/pyqasm のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 63/100
メンテナーはふだん 1 日以内に返信
-
enhancement error-handling program-validation
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
メンテナーはふだん 1 日以内に返信
-
Move the QASM 2 printer and its branch pre-processing out of qasm2.py対応中かも @danielgaskins が 8 日前に担当しました。 オープンenhancement qasm2
難易度 4/5 3〜5日 初心者へのやさしさ 22/100
qBraid/pyqasm#447 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
Parse failures raise ValidationError with an empty message; the ANTLR diagnostic is lost対応中かも @tonycoder-hub が 10 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 22/100
qBraid/pyqasm#436 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
`extern port` / `extern frame` in `cal` blocks fail to parse, blocking nearly every spec OpenPulse example対応中かも @Riiocodee が 2 日前に担当しました。 オープンbug llm-assisted qasm3 qasm3-coverage
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
qBraid/pyqasm#401 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
似ている issue
-
comp/tools P2 type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NousResearch/hermes-agent#142908 · コメント 1 件 ·
-
[oblt-aw][autodoc] Fix malformed headings in new Buildkite docs pages対応中かも @github-actions が今日担当しました。 オープンdocumentation
難易度 1/5 1時間未満 初心者へのやさしさ 83/100
メンテナーはふだん 1 日以内に返信
-
[Bug]: fileUploadMatrix.test.ts URL case does a real DNS lookup and fails offline対応中かも @r2jaff が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
ComposioHQ/composio#5054 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
pytorch/tensordict#3286 ·
メンテナーはふだん 1 日以内に返信