Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Aperta
#438 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@Jah-yee ci sta già lavorando.

Dal 5/10/2026.

  • #446 di @Jah-yee — chiusa senza merge
  • #450 di @Jah-yee — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
python
Ambito
compilers

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Python
Stelle
29
Fork
33
Merge medio
2g 4h
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di qBraid/pyqasm

Tutte le issue di qBraid/pyqasm

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.