From bb06ae0224266f59ca7e6a409f40e5d0781c2e14 Mon Sep 17 00:00:00 2001 From: John Lapeyre Date: Thu, 18 Jan 2024 21:20:20 -0500 Subject: [PATCH] Set type of measurement expression correctly That is measuring a qubit or hardware qubit results in a bit. Measuring a qubit register results in a bit register of the same length. Closes #51 --- crates/oq3_semantics/src/asg.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/crates/oq3_semantics/src/asg.rs b/crates/oq3_semantics/src/asg.rs index d69ea14..27d8e4d 100644 --- a/crates/oq3_semantics/src/asg.rs +++ b/crates/oq3_semantics/src/asg.rs @@ -578,10 +578,16 @@ impl MeasureExpression { &self.operand } - // FIXME: type may not be correct here. - // This assumes a single qubit is measured. pub fn to_texpr(self) -> TExpr { - TExpr::new(Expr::MeasureExpression(self), Type::Bit(IsConst::False)) + let out_type = match self.operand.get_type() { + Type::Qubit | Type::HardwareQubit => Type::Bit(IsConst::False), + Type::QubitArray(dims) => Type::BitArray(dims.clone(), IsConst::False), + _ => panic!( + "Measure expression operand has type {:?}", + self.operand.get_type() + ), + }; + TExpr::new(Expr::MeasureExpression(self), out_type) } }