Skip to content

Commit

Permalink
Change assert and instead raise diagnostics error (#34)
Browse files Browse the repository at this point in the history
Assertions cause EOFFailure in the compiler and this PR fixes one such
assert.
  • Loading branch information
SooluThomas authored Mar 26, 2024
1 parent a9cf9fa commit f6d695f
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions lib/AST/ASTGates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,15 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id,
++C;
}

assert(C == Params.size() && "Inconsistent number of Params!");
if (C != Params.size()) {
std::stringstream M;
M << C
<< " inconsistent parameters in the gate call for the "
"corresponding gate definition";
QasmDiagnosticEmitter::Instance().EmitDiagnostic(
DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error);
return;
}

C = 0;
Ty = ASTTypeUndefined;
Expand Down Expand Up @@ -1363,7 +1371,15 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id,
++C;
}

assert(C == Params.size() && "Inconsistent number of Params!");
if (C != Params.size()) {
std::stringstream M;
M << C
<< " inconsistent parameters in the gate call for the "
"corresponding gate definition";
QasmDiagnosticEmitter::Instance().EmitDiagnostic(
DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error);
return;
}

for (std::vector<ASTAngleNode *>::const_iterator I = Params.begin();
I != Params.end(); ++I) {
Expand Down

0 comments on commit f6d695f

Please sign in to comment.