From f6d695fd9f18462e65f6290d05ccb4ccb371b288 Mon Sep 17 00:00:00 2001 From: Soolu Thomas Date: Tue, 26 Mar 2024 14:27:20 -0400 Subject: [PATCH] Change assert and instead raise diagnostics error (#34) Assertions cause EOFFailure in the compiler and this PR fixes one such assert. --- lib/AST/ASTGates.cpp | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/AST/ASTGates.cpp b/lib/AST/ASTGates.cpp index e012309..46a353e 100644 --- a/lib/AST/ASTGates.cpp +++ b/lib/AST/ASTGates.cpp @@ -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; @@ -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::const_iterator I = Params.begin(); I != Params.end(); ++I) {