Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[BUG] dumps() emits extern calls without a semicolon, producing unparsable QASM

オープン
#438 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@Jah-yee がすでに取り組んでいます。

2026年10月5日 から。

  • #446 @Jah-yee による — マージされずにクローズ
  • #450 @Jah-yee による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python
領域
compilers

調査の方向性

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 の本文から書いたものです。

説明

bug
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

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

qBraid/pyqasm のほかの issue

qBraid/pyqasm の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。