Skip to content

Commit f6d695f

Browse files
authored
Change assert and instead raise diagnostics error (#34)
Assertions cause EOFFailure in the compiler and this PR fixes one such assert.
1 parent a9cf9fa commit f6d695f

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

lib/AST/ASTGates.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1131,7 +1131,15 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id,
11311131
++C;
11321132
}
11331133

1134-
assert(C == Params.size() && "Inconsistent number of Params!");
1134+
if (C != Params.size()) {
1135+
std::stringstream M;
1136+
M << C
1137+
<< " inconsistent parameters in the gate call for the "
1138+
"corresponding gate definition";
1139+
QasmDiagnosticEmitter::Instance().EmitDiagnostic(
1140+
DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error);
1141+
return;
1142+
}
11351143

11361144
C = 0;
11371145
Ty = ASTTypeUndefined;
@@ -1363,7 +1371,15 @@ ASTGateNode::ASTGateNode(const ASTIdentifierNode *Id,
13631371
++C;
13641372
}
13651373

1366-
assert(C == Params.size() && "Inconsistent number of Params!");
1374+
if (C != Params.size()) {
1375+
std::stringstream M;
1376+
M << C
1377+
<< " inconsistent parameters in the gate call for the "
1378+
"corresponding gate definition";
1379+
QasmDiagnosticEmitter::Instance().EmitDiagnostic(
1380+
DIAGLineCounter::Instance().GetLocation(), M.str(), DiagLevel::Error);
1381+
return;
1382+
}
13671383

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

0 commit comments

Comments
 (0)