@@ -1300,6 +1300,11 @@ if (!dict) {
13001300 emitError() << "expected DictionaryAttr to set properties";
13011301 return ::mlir::failure();
13021302}
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;
13031308)decl" ;
13041309
13051310 // {0}: fromAttribute call
@@ -1310,6 +1315,7 @@ auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr,
13101315 ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult {{
13111316 {0};
13121317};
1318+ usedKeys.insert(StringAttr::get(ctx, "{1}"));
13131319auto attr = dict.get("{1}");
13141320if (!attr && {2}) {{
13151321 emitError() << "expected key entry for {1} in DictionaryAttr to set "
@@ -1357,6 +1363,7 @@ if (attr && ::mlir::failed(setFromAttr(prop.{1}, attr, emitError)))
13571363 body << formatv (R"decl(
13581364auto &propStorage = prop.{0};
13591365auto attr = dict.get("{0}");
1366+ usedKeys.insert(StringAttr::get(ctx, "{0}"));
13601367if (attr || /*isRequired=*/{1}) {{
13611368 if (!attr) {{
13621369 emitError() << "expected key entry for {0} in DictionaryAttr to set "
@@ -1374,7 +1381,14 @@ if (attr || /*isRequired=*/{1}) {{
13741381)decl" ,
13751382 namedAttr.name , isRequired);
13761383 }
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 dictionary";
1389+ }
1390+ return ::mlir::success();
1391+ )decl" ;
13781392}
13791393
13801394void OperationFormat::genParser (Operator &op, OpClass &opClass) {
0 commit comments