Skip to content

fix: add missing semicolon after extern function call in dumps() output - #446

Closed
Jah-yee wants to merge 3 commits into
qBraid:mainfrom
Jah-yee:fix/extern-call-semicolon
Closed

Jah-yee wants to merge 3 commits into
qBraid:mainfrom
Jah-yee:fix/extern-call-semicolon

Conversation

@Jah-yee

@Jah-yee Jah-yee commented Oct 5, 2026

Copy link
Copy Markdown

Summary

When an extern function is called as a bare statement (not assigned to a variable), e.g.:

OPENQASM 3.0;
extern my_extern(int);
my_extern(3);

pyqasm.dumps() emitted the call without a terminating semicolon, making the output unparsable by openqasm3.parse().

Root cause

In _visit_function_call (visitor.py), when the subroutine is an ExternDeclaration, the raw FunctionCall node was appended to the result list. The openqasm3.printer.Printer.visit_FunctionCall method does not add a semicolon — that is done by visit_ExpressionStatement via _end_statement. Bare FunctionCall nodes were visited directly, missing the semicolon.

Fix

Wrap the extern FunctionCall in qasm3_ast.ExpressionStatement before appending to the result list, ensuring the printer correctly adds the semicolon.

Testing

Verified with the reproducer from issue #438: the output now parses cleanly with openqasm3.parse().

Fixes #438.

… input

Fixes Issue qBraid#437: loads('') now raises ValidationError (consistent
with other invalid inputs) instead of AttributeError when openqasm3
parser encounters malformed/empty input and returns None for node.stop.line.

GH007: Jah-yee <jydu_seven@outlook.com>
Fixes qBraid#437: loads('') now raises ValidationError instead of AttributeError.
When an extern function is called as a bare statement (not assigned to a
variable), pyqasm returned the raw FunctionCall node from
_visit_function_call. The openqasm3 printer's visit_FunctionCall does not
add a terminating semicolon; that is done by visit_ExpressionStatement via
_end_statement. This caused dumps() to emit extern call lines without
semicolons, making the output unparsable by openqasm3.parse.

Fix: wrap the extern FunctionCall in qasm3_ast.ExpressionStatement before
appending to the result list, so the printer correctly adds the semicolon.

Fixes qBraid#438.
Co-authored-by: Jah-yee <166608075+Jah-yee@users.noreply.github.com>
@Jah-yee
Jah-yee requested a review from TheGupta2012 as a code owner October 5, 2026 00:26
@argus-eye

argus-eye Bot commented Oct 5, 2026

Copy link
Copy Markdown

Argus review

Auto-review is off for this repo. Tick the box below to run a review on this PR.

  • Trigger Argus review

Estimated cost

  • Files changed: 3
  • Diff lines (±): 10
  • Historical avg: ~350.5k tokens · ~$1.38 · across last 13 review(s)

Tip: you can also comment @argus-eye review at any time.

@coderabbitai

coderabbitai Bot commented Oct 5, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Repository: qBraid/pyqasm/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 154ab0a9-06c9-42ad-8d8e-df001f9741b0

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@TheGupta2012

TheGupta2012 commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Hi @Jah-yee , thanks for this change! Change looks good overall just a couple of things -

  1. Can you please add tests for validating this change as well? We want to ensure that there are examples with extern statements ending with ; in our test suite.
  2. Also, I saw that you fixed empty string parsing errors. Is that a related fix? If not, please just keep the scope to fixing the extern output.

I also do not see any CI checks, can you please push another commit? I will approve the CI run then

@Jah-yee Jah-yee closed this Oct 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants