Skip to content

Commit 6a9bb82

Browse files
Fix equality so that if using on two different types won't try to upcast
1 parent f10a47f commit 6a9bb82

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

python/egglog/runtime.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -584,11 +584,17 @@ def __eq__(self, other: object) -> object: # type: ignore[override]
584584
if (method := _get_expr_method(self, "__eq__")) is not None:
585585
return method(other)
586586

587-
# TODO: Check if two objects can be upcasted to be the same. If not, then return NotImplemented so other
588-
# expr gets a chance to resolve __eq__ which could be a preserved method.
589-
from .egraph import BaseExpr, eq # noqa: PLC0415
587+
if not (isinstance(self, RuntimeExpr) and isinstance(other, RuntimeExpr)):
588+
return NotImplemented
589+
if self.__egg_typed_expr__.tp != other.__egg_typed_expr__.tp:
590+
return NotImplemented
590591

591-
return eq(cast("BaseExpr", self)).to(cast("BaseExpr", other))
592+
from .egraph import Fact # noqa: PLC0415
593+
594+
return Fact(
595+
Declarations.create(self, other),
596+
EqDecl(self.__egg_typed_expr__.tp, self.__egg_typed_expr__.expr, other.__egg_typed_expr__.expr),
597+
)
592598

593599
def __ne__(self, other: object) -> object: # type: ignore[override]
594600
if (method := _get_expr_method(self, "__ne__")) is not None:

0 commit comments

Comments
 (0)