Skip to content

Commit

Permalink
Be more accurate in locating source for mismatch in gate signature error
Browse files Browse the repository at this point in the history
Locate error in either qubit list or param list, if they are non-empty.
Otherwise in the gate name. These apply when the signature of the defined
gate does not match that of the called gate.
  • Loading branch information
jlapeyre committed Jan 21, 2024
1 parent b712853 commit 3321d06
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions crates/oq3_semantics/src/syntax_to_semantics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -501,10 +501,23 @@ fn from_item(item: synast::Item, context: &mut Context) -> Option<asg::Stmt> {
_ => (0, 0),
};
if def_num_params != num_params.try_into().unwrap() {
context.insert_error(NumGateParamsError, &gate_call);
if num_params != 0 {
// If num params is mismatched, locate error at list of params supplied.
context.insert_error(NumGateParamsError, &gate_call.arg_list().unwrap());
} else {
// If no params are supplied, but some are expected, locate error at gate name.
context.insert_error(NumGateParamsError, &gate_id.unwrap());
}
}
if def_num_qubits != gate_operands.len().try_into().unwrap() {
context.insert_error(NumGateQubitsError, &gate_call);
let num_qubits: usize = gate_operands.len();
if def_num_qubits != num_qubits.try_into().unwrap() {
if num_qubits == 0 {
// This probably can't happen because no qubit args is not recognized syntactially
// as a gate call.
context.insert_error(NumGateQubitsError, &gate_call);
} else {
context.insert_error(NumGateQubitsError, &gate_call.qubit_list().unwrap());
};
}
} else if symbol_result.is_ok() {
// If symbol_result.is_err then we have already logged UndefGateError.
Expand Down

0 comments on commit 3321d06

Please sign in to comment.