From 8676ccc533ed418ea7f7da593daec8d3a4dc9950 Mon Sep 17 00:00:00 2001 From: rihi <19492038+rihi@users.noreply.github.com> Date: Wed, 4 Sep 2024 13:55:40 +0200 Subject: [PATCH] Fix hash for complex types --- decompiler/structures/pseudo/complextypes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/decompiler/structures/pseudo/complextypes.py b/decompiler/structures/pseudo/complextypes.py index 3c304053..90d2e6dd 100644 --- a/decompiler/structures/pseudo/complextypes.py +++ b/decompiler/structures/pseudo/complextypes.py @@ -79,6 +79,10 @@ def declaration(self) -> str: members = ";\n\t".join(self.members[k].declaration() for k in sorted(self.members.keys())) + ";" return f"{self.type_specifier.value} {self.name} {{\n\t{members}\n}}" + def __hash__(self) -> int: + # Because dict is not hashable, we need our own hash implementation + return hash(repr(self)) + @dataclass(frozen=True, order=True) class Struct(_BaseStruct): @@ -117,6 +121,10 @@ def get_member_name_by_type(self, _type: Type) -> str: logging.warning(f"Cannot get member name for union {self}") return "unknown_field" + def __hash__(self) -> int: + # Because list is not hashable, we need our own hash implementation + return hash(repr(self)) + @dataclass(frozen=True, order=True) class Enum(ComplexType): @@ -134,6 +142,10 @@ def declaration(self) -> str: members = ",\n\t".join(f"{x.name} = {x.value}" for x in self.members.values()) return f"{self.type_specifier.value} {self.name} {{\n\t{members}\n}}" + def __hash__(self) -> int: + # Because dict is not hashable, we need our own hash implementation + return hash(repr(self)) + @dataclass(frozen=True, order=True) class ComplexTypeName(Type):