@@ -1300,6 +1300,11 @@ if (!dict) {
1300
1300
emitError() << "expected DictionaryAttr to set properties";
1301
1301
return ::mlir::failure();
1302
1302
}
1303
+ // keep track of used keys in the input dictionnary to be able to error out
1304
+ // if there are some unknown ones.
1305
+ DenseSet<StringAttr> usedKeys;
1306
+ MLIRContext *ctx = dict.getContext();
1307
+ (void)ctx;
1303
1308
)decl" ;
1304
1309
1305
1310
// {0}: fromAttribute call
@@ -1310,6 +1315,7 @@ auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr,
1310
1315
::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult {{
1311
1316
{0};
1312
1317
};
1318
+ usedKeys.insert(StringAttr::get(ctx, "{1}"));
1313
1319
auto attr = dict.get("{1}");
1314
1320
if (!attr && {2}) {{
1315
1321
emitError() << "expected key entry for {1} in DictionaryAttr to set "
@@ -1357,6 +1363,7 @@ if (attr && ::mlir::failed(setFromAttr(prop.{1}, attr, emitError)))
1357
1363
body << formatv (R"decl(
1358
1364
auto &propStorage = prop.{0};
1359
1365
auto attr = dict.get("{0}");
1366
+ usedKeys.insert(StringAttr::get(ctx, "{0}"));
1360
1367
if (attr || /*isRequired=*/{1}) {{
1361
1368
if (!attr) {{
1362
1369
emitError() << "expected key entry for {0} in DictionaryAttr to set "
@@ -1374,7 +1381,14 @@ if (attr || /*isRequired=*/{1}) {{
1374
1381
)decl" ,
1375
1382
namedAttr.name , isRequired);
1376
1383
}
1377
- body << " return ::mlir::success();\n " ;
1384
+ body << R"decl(
1385
+ for (NamedAttribute attr : dict) {
1386
+ if (!usedKeys.contains(attr.getName()))
1387
+ return emitError() << "Unknown key '" << attr.getName() <<
1388
+ "' when parsing properties dictionnary";
1389
+ }
1390
+ return ::mlir::success();
1391
+ )decl" ;
1378
1392
}
1379
1393
1380
1394
void OperationFormat::genParser (Operator &op, OpClass &opClass) {
0 commit comments