@@ -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 dictionary 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,7 +1315,9 @@ auto setFromAttr = [] (auto &propStorage, ::mlir::Attribute propAttr,
13101315 ::llvm::function_ref<::mlir::InFlightDiagnostic()> emitError) -> ::mlir::LogicalResult {{
13111316 {0};
13121317};
1313- auto attr = dict.get("{1}");
1318+ auto {1}AttrName = StringAttr::get(ctx, "{1}");
1319+ usedKeys.insert({1}AttrName);
1320+ auto attr = dict.get({1}AttrName);
13141321if (!attr && {2}) {{
13151322 emitError() << "expected key entry for {1} in DictionaryAttr to set "
13161323 "Properties.";
@@ -1356,7 +1363,9 @@ if (attr && ::mlir::failed(setFromAttr(prop.{1}, attr, emitError)))
13561363 bool isRequired = !attr.isOptional () && !attr.hasDefaultValue ();
13571364 body << formatv (R"decl(
13581365auto &propStorage = prop.{0};
1359- auto attr = dict.get("{0}");
1366+ auto {0}AttrName = StringAttr::get(ctx, "{0}");
1367+ auto attr = dict.get({0}AttrName);
1368+ usedKeys.insert(StringAttr::get(ctx, "{1}"));
13601369if (attr || /*isRequired=*/{1}) {{
13611370 if (!attr) {{
13621371 emitError() << "expected key entry for {0} in DictionaryAttr to set "
@@ -1374,7 +1383,14 @@ if (attr || /*isRequired=*/{1}) {{
13741383)decl" ,
13751384 namedAttr.name , isRequired);
13761385 }
1377- body << " return ::mlir::success();\n " ;
1386+ body << R"decl(
1387+ for (NamedAttribute attr : dict) {
1388+ if (!usedKeys.contains(attr.getName()))
1389+ return emitError() << "unknown key '" << attr.getName() <<
1390+ "' when parsing properties dictionary";
1391+ }
1392+ return ::mlir::success();
1393+ )decl" ;
13781394}
13791395
13801396void OperationFormat::genParser (Operator &op, OpClass &opClass) {
0 commit comments