Skip to content

Commit 472c824

Browse files
authored
fix hash(-1) == hash(-2) collision (#412)
thank you Guildo, I'm confident using Python again
1 parent eb5622e commit 472c824

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/kirin/ir/attrs/py.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def __init__(self, data: T, pytype: TypeAttribute | None = None):
3535
self.type = pytype
3636

3737
def __hash__(self):
38+
# Fix hash(-1) == hash(-2) collision
39+
if isinstance(self.data, int):
40+
return self.data
3841
return hash(self.data) + hash(self.type)
3942

4043
def print_impl(self, printer: Printer) -> None:

0 commit comments

Comments
 (0)