diff --git a/mlir/lib/Bindings/Python/IRCore.cpp b/mlir/lib/Bindings/Python/IRCore.cpp --- a/mlir/lib/Bindings/Python/IRCore.cpp +++ b/mlir/lib/Bindings/Python/IRCore.cpp @@ -1566,7 +1566,7 @@ mlirOperationEqual(self.getParentOperation()->get(), mlirOpResultGetOwner(self.get())) && "expected the owner of the value in Python to match that in the IR"); - return self.getParentOperation(); + return self.getParentOperation().getObject(); }); c.def_property_readonly("result_number", [](PyOpResult &self) { return mlirOpResultGetResultNumber(self.get()); diff --git a/mlir/test/Bindings/Python/ir_value.py b/mlir/test/Bindings/Python/ir_value.py --- a/mlir/test/Bindings/Python/ir_value.py +++ b/mlir/test/Bindings/Python/ir_value.py @@ -25,3 +25,16 @@ run(testCapsuleConversions) + + +# CHECK-LABEL: TEST: testOpResultOwner +def testOpResultOwner(): + ctx = Context() + ctx.allow_unregistered_dialects = True + with Location.unknown(ctx): + i32 = IntegerType.get_signless(32) + op = Operation.create("custom.op1", results=[i32]) + assert op.result.owner == op + + +run(testOpResultOwner)