|
21 | 21 | #include "llvm/Support/SMLoc.h" |
22 | 22 | #include <optional> |
23 | 23 |
|
| 24 | +namespace { |
| 25 | +// reference https://stackoverflow.com/a/16000226 |
| 26 | +template <typename T, typename = void> |
| 27 | +struct HasStaticName : std::false_type {}; |
| 28 | + |
| 29 | +template <typename T> |
| 30 | +struct HasStaticName<T, |
| 31 | + typename std::enable_if< |
| 32 | + std::is_same<::llvm::StringLiteral, |
| 33 | + std::decay_t<decltype(T::name)>>::value, |
| 34 | + void>::type> : std::true_type {}; |
| 35 | +} // namespace |
| 36 | + |
24 | 37 | namespace mlir { |
25 | 38 | class AsmParsedResourceEntry; |
26 | 39 | class AsmResourceBuilder; |
@@ -1238,8 +1251,13 @@ class AsmParser { |
1238 | 1251 |
|
1239 | 1252 | // Check for the right kind of type. |
1240 | 1253 | result = llvm::dyn_cast<TypeT>(type); |
1241 | | - if (!result) |
1242 | | - return emitError(loc, "invalid kind of type specified"); |
| 1254 | + if (!result) { |
| 1255 | + InFlightDiagnostic diag = |
| 1256 | + emitError(loc, "invalid kind of type specified"); |
| 1257 | + if constexpr (HasStaticName<TypeT>::value) |
| 1258 | + diag << ": expected " << TypeT::name << ", but found " << type; |
| 1259 | + return diag; |
| 1260 | + } |
1243 | 1261 |
|
1244 | 1262 | return success(); |
1245 | 1263 | } |
@@ -1270,8 +1288,13 @@ class AsmParser { |
1270 | 1288 |
|
1271 | 1289 | // Check for the right kind of Type. |
1272 | 1290 | result = llvm::dyn_cast<TypeT>(type); |
1273 | | - if (!result) |
1274 | | - return emitError(loc, "invalid kind of Type specified"); |
| 1291 | + if (!result) { |
| 1292 | + InFlightDiagnostic diag = |
| 1293 | + emitError(loc, "invalid kind of type specified"); |
| 1294 | + if constexpr (HasStaticName<TypeT>::value) |
| 1295 | + diag << ": expected " << TypeT::name << ", but found " << type; |
| 1296 | + return diag; |
| 1297 | + } |
1275 | 1298 | return success(); |
1276 | 1299 | } |
1277 | 1300 |
|
@@ -1307,8 +1330,13 @@ class AsmParser { |
1307 | 1330 |
|
1308 | 1331 | // Check for the right kind of type. |
1309 | 1332 | result = llvm::dyn_cast<TypeType>(type); |
1310 | | - if (!result) |
1311 | | - return emitError(loc, "invalid kind of type specified"); |
| 1333 | + if (!result) { |
| 1334 | + InFlightDiagnostic diag = |
| 1335 | + emitError(loc, "invalid kind of type specified"); |
| 1336 | + if constexpr (HasStaticName<TypeType>::value) |
| 1337 | + diag << ": expected " << TypeType::name << ", but found " << type; |
| 1338 | + return diag; |
| 1339 | + } |
1312 | 1340 |
|
1313 | 1341 | return success(); |
1314 | 1342 | } |
|
0 commit comments