Skip to content

Commit

Permalink
Add support for complex numbers as dictionary keys
Browse files Browse the repository at this point in the history
  • Loading branch information
mzagozen committed Jan 9, 2025
1 parent 32bae46 commit 0f5911f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/src/__builtin__.ext.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ void B___ext_init__() {
B_HashableD_floatG_methods.__eq__ = (B_bool (*)(B_HashableD_float, B_float, B_float))B_OrdD_floatD___eq__;
B_HashableD_strG_methods.__eq__ = (B_bool (*)(B_HashableD_str, B_str, B_str))B_OrdD_strD___eq__;
B_HashableD_bytesG_methods.__eq__ = (B_bool (*)(B_HashableD_bytes, B_bytes, B_bytes))B_OrdD_bytesD___eq__;
B_HashableD_complexG_methods.__eq__ = (B_bool (*)(B_HashableD_complex, B_complex, B_complex))B_HashableD_complexD___eq__;

B_ContainerD_listG_methods.__len__ = (B_int (*)(B_ContainerD_list, B_list))B_CollectionD_SequenceD_listD___len__;
B_ContainerD_listG_methods.__fromiter__ = (B_list (*)(B_ContainerD_list, B_Iterable, $WORD))B_CollectionD_SequenceD_listD___fromiter__;
Expand Down
8 changes: 8 additions & 0 deletions test/builtins_auto/test_complex.act
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,14 @@ def test_complex() -> bool:
print("Small number multiplication failed to handle underflow correctly")
return False

# Test complex number as dictionary key
d = {}
d[c2] = 42
d[c3] = 43
if not (d[c2] == 42 and d[c3] == 43):
print("Complex number as dictionary key failed")
return False

return True

actor main(env):
Expand Down

0 comments on commit 0f5911f

Please sign in to comment.