@@ -1189,4 +1189,86 @@ TEST(EvaluatorTests, ListConcatField) {
11891189 .getValue ());
11901190}
11911191
1192+ TEST (EvaluatorTests, NestedReferenceValue) {
1193+ StringRef mod =
1194+ " om.class @Empty() {"
1195+ " om.class.fields"
1196+ " }"
1197+ " om.class @Any() -> (object: !om.any, string: !om.any) {"
1198+ " %0 = om.object @Empty() : () -> !om.class.type<@Empty>"
1199+ " %1 = om.any_cast %0 : (!om.class.type<@Empty>) -> !om.any"
1200+ " %2 = om.constant \" foo\" : !om.string"
1201+ " %3 = om.any_cast %2 : (!om.string) -> !om.any"
1202+ " om.class.fields %1, %3 : !om.any, !om.any"
1203+ " }"
1204+ " om.class @InnerClass1(%anyListIn: !om.list<!om.any>) -> (any_list1: "
1205+ " !om.list<!om.any>) {"
1206+ " om.class.fields %anyListIn : !om.list<!om.any>"
1207+ " }"
1208+ " om.class @InnerClass2(%anyListIn: !om.list<!om.any>) -> (any_list2: "
1209+ " !om.list<!om.any>) {"
1210+ " om.class.fields %anyListIn : !om.list<!om.any>"
1211+ " }"
1212+ " om.class @OuterClass2() -> (om: !om.class.type<@InnerClass2>) {"
1213+ " %0 = om.object @InnerClass2(%5) : (!om.list<!om.any>) -> "
1214+ " !om.class.type<@InnerClass2>"
1215+ " %1 = om.object @Any() : () -> !om.class.type<@Any>"
1216+ " %2 = om.object.field %1, [@object] : (!om.class.type<@Any>) -> "
1217+ " !om.any"
1218+ " %3 = om.object @Any() : () -> !om.class.type<@Any>"
1219+ " %4 = om.object.field %3, [@object] : (!om.class.type<@Any>) -> "
1220+ " !om.any"
1221+ " %5 = om.list_create %2, %4 : !om.any"
1222+ " om.class.fields %0 : !om.class.type<@InnerClass2>"
1223+ " }"
1224+ " om.class @OuterClass1() -> (om: !om.any) {"
1225+ " %0 = om.object @InnerClass1(%8) : (!om.list<!om.any>) -> "
1226+ " !om.class.type<@InnerClass1>"
1227+ " %1 = om.any_cast %0 : (!om.class.type<@InnerClass1>) -> !om.any"
1228+ " %2 = om.object @OuterClass2() : () -> !om.class.type<@OuterClass2>"
1229+ " %3 = om.object.field %2, [@om] : (!om.class.type<@OuterClass2>) -> "
1230+ " !om.class.type<@InnerClass2>"
1231+ " %4 = om.any_cast %3 : (!om.class.type<@InnerClass2>) -> !om.any"
1232+ " %5 = om.object @OuterClass2() : () -> !om.class.type<@OuterClass2>"
1233+ " %6 = om.object.field %5, [@om] : (!om.class.type<@OuterClass2>) -> "
1234+ " !om.class.type<@InnerClass2>"
1235+ " %7 = om.any_cast %6 : (!om.class.type<@InnerClass2>) -> !om.any"
1236+ " %8 = om.list_create %4, %7 : !om.any"
1237+ " om.class.fields %1 : !om.any"
1238+ " }" ;
1239+
1240+ DialectRegistry registry;
1241+ registry.insert <OMDialect>();
1242+
1243+ MLIRContext context (registry);
1244+ context.getOrLoadDialect <OMDialect>();
1245+
1246+ OwningOpRef<ModuleOp> owning =
1247+ parseSourceString<ModuleOp>(mod, ParserConfig (&context));
1248+
1249+ Evaluator evaluator (owning.release ());
1250+
1251+ auto result =
1252+ evaluator.instantiate (StringAttr::get (&context, " OuterClass1" ), {});
1253+
1254+ ASSERT_TRUE (succeeded (result));
1255+
1256+ ASSERT_TRUE (isa<evaluator::ObjectValue>(
1257+ llvm::cast<evaluator::ListValue>(
1258+ llvm::cast<evaluator::ObjectValue>(
1259+ llvm::cast<evaluator::ListValue>(
1260+ llvm::cast<evaluator::ObjectValue>(
1261+ llvm::cast<evaluator::ObjectValue>(result->get ())
1262+ ->getField (" om" )
1263+ ->get ())
1264+ ->getField (" any_list1" )
1265+ ->get ())
1266+ ->getElements ()[0 ]
1267+ .get ())
1268+ ->getField (" any_list2" )
1269+ ->get ())
1270+ ->getElements ()[0 ]
1271+ .get ()));
1272+ }
1273+
11921274} // namespace
0 commit comments