Qiskit / openqasm3_parser

Parser and semantic analyzer for the OpenQASM3 language
Apache License 2.0
11 stars 12 forks source link

Single-statement `for` loop causes panic #182

Open jlapeyre opened 7 months ago

jlapeyre commented 7 months ago

Version 0.4.0

These methods look for either a single statement or a body. If the body is not found, it should return None. https://github.com/Qiskit/openqasm3_parser/blob/22b55cc1582f1c98180099dca1f224d0fab11fd8/crates/oq3_syntax/src/ast/generated/nodes.rs#L270-L275

But when constructing the ASG, the final representation of the OQ3 program, we erroneously assume that the for statement loops over a block and never over a single statement: https://github.com/Qiskit/openqasm3_parser/blob/22b55cc1582f1c98180099dca1f224d0fab11fd8/crates/oq3_semantics/src/syntax_to_semantics.rs#L245

In case there is no block, the unwrap causes a panic.