From 0f5911f1de43a56bf70e4d23b258eb753ecd61dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Zago=C5=BEen?= Date: Thu, 9 Jan 2025 22:10:48 +0100 Subject: [PATCH] Add support for complex numbers as dictionary keys --- base/src/__builtin__.ext.c | 1 + test/builtins_auto/test_complex.act | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/base/src/__builtin__.ext.c b/base/src/__builtin__.ext.c index cef6fe230..57ce5db25 100644 --- a/base/src/__builtin__.ext.c +++ b/base/src/__builtin__.ext.c @@ -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__; diff --git a/test/builtins_auto/test_complex.act b/test/builtins_auto/test_complex.act index 3717b2586..a2f95c258 100644 --- a/test/builtins_auto/test_complex.act +++ b/test/builtins_auto/test_complex.act @@ -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):