Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#438 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@Jah-yee đang làm issue này rồi.

Từ ngày 5/10/2026.

  • #446 của @Jah-yee — đã đóng, không merge
  • #450 của @Jah-yee — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
compilers

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
29
Fork
33
Merge trung bình
2 ngày 4 giờ
Pull request đã merge (30 ngày)
15

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của qBraid/pyqasm

Tất cả issue của qBraid/pyqasm

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.