diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h index 96c8f3d79c5e0..e66f149b6f812 100644 --- a/mlir/include/mlir/IR/OpImplementation.h +++ b/mlir/include/mlir/IR/OpImplementation.h @@ -1165,14 +1165,15 @@ class AsmParser { typename = std::enable_if_t::value>> OptionalParseResult parseOptionalAttribute(AttrType &result, Type type = {}) { + llvm::SMLoc loc = getCurrentLocation(); Attribute attr; OptionalParseResult parseResult = parseOptionalAttribute(attr, type); if (!parseResult.has_value() || failed(*parseResult)) return parseResult; result = dyn_cast(attr); if (!result) - return emitError(getCurrentLocation()) - << "expected attribute of a different type"; + return emitError(loc) << "expected attribute of type '" << AttrType::name + << "', but found attribute '" << attr << "'"; return success(); } diff --git a/mlir/test/IR/invalid-custom-print-parse.mlir b/mlir/test/IR/invalid-custom-print-parse.mlir index 41e8d97e1db49..774af05943817 100644 --- a/mlir/test/IR/invalid-custom-print-parse.mlir +++ b/mlir/test/IR/invalid-custom-print-parse.mlir @@ -29,7 +29,7 @@ test.op_with_enum_prop_attr_form <{value = 0 : i32, foo}> // Test that an integer literal cannot be used where an APFloat is expected. // parseOptionalAttribute(FloatAttr &) should reject a non-float attribute. -// expected-error@+2 {{expected attribute of a different type}} +// expected-error@+2 {{expected attribute of type 'builtin.float', but found attribute '5 : i64'}} // expected-error@+1 {{failed to parse TestTypeAPFloat parameter}} func.func private @test_ap_float_wrong_attr_type() -> !test.ap_float<5U0>