[Mlir-commits] [mlir] [mlir] Improve error message when number of operands and types differ (PR #118488)
Markus Böck
llvmlistbot at llvm.org
Tue Dec 3 07:47:57 PST 2024
================
@@ -1602,14 +1602,33 @@ class OpAsmParser : public AsmParser {
SmallVectorImpl<Value> &result) {
size_t operandSize = llvm::range_size(operands);
size_t typeSize = llvm::range_size(types);
- if (operandSize != typeSize)
- return emitError(loc)
- << operandSize << " operands present, but expected " << typeSize;
+ if (operandSize == typeSize) {
+ for (auto [operand, type] : llvm::zip_equal(operands, types))
+ if (resolveOperand(operand, type, result))
+ return failure();
+ return success();
+ }
- for (auto [operand, type] : llvm::zip_equal(operands, types))
- if (resolveOperand(operand, type, result))
- return failure();
- return success();
+ InFlightDiagnostic diag = emitError(loc)
+ << "number of operands and types do not match";
+ std::string lesserQuantityText = "operand";
+ if (operandSize != 1)
+ lesserQuantityText += "s";
+ std::string higherQuantityText = "type";
+ if (typeSize != 1)
+ higherQuantityText += "s";
+
+ size_t lesserQuantity = operandSize;
+ size_t higherQuantity = typeSize;
+ if (operandSize > typeSize) {
+ std::swap(lesserQuantity, higherQuantity);
+ std::swap(lesserQuantityText, higherQuantityText);
+ }
+
+ diag.attachNote() << "got " << higherQuantity << " " << higherQuantityText
+ << " but only " << lesserQuantity << " "
+ << lesserQuantityText;
----------------
zero9178 wrote:
I don't feel super strong about either options, so if you feel the current version is worse or not worth the extra implementation complexity I can gladly change it!
https://github.com/llvm/llvm-project/pull/118488
More information about the Mlir-commits
mailing list