From 229c737e0c86436a3c948155e8e6c1e982a04ca8 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 24 Jul 2023 19:15:33 +0530 Subject: [PATCH 1/2] ASR: Return nullptr for None return type in Callback --- src/lpython/semantics/python_ast_to_asr.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index c4466d2bd7..ac31a64003 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -1703,6 +1703,10 @@ class CommonVisitor : public AST::BaseVisitor { abi, is_argument); } + if (AST::is_a(annotation)) { + return nullptr; + } + if (AST::is_a(annotation)) { AST::Subscript_t *s = AST::down_cast(&annotation); if (AST::is_a(*s->m_value)) { From b7f9127d038953c42ff64662ac2bf71cddecf639 Mon Sep 17 00:00:00 2001 From: Shaikh Ubaid Date: Mon, 24 Jul 2023 19:16:31 +0530 Subject: [PATCH 2/2] TESTS: For callback with None return type --- integration_tests/CMakeLists.txt | 1 + integration_tests/callback_03.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 integration_tests/callback_03.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index c9e12e97a6..3178636e29 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -722,6 +722,7 @@ RUN(NAME global_syms_06 LABELS cpython llvm c) RUN(NAME callback_01 LABELS cpython llvm c) RUN(NAME callback_02 LABELS cpython llvm c) +RUN(NAME callback_03 LABELS cpython llvm c) # Intrinsic Functions RUN(NAME intrinsics_01 LABELS cpython llvm NOFAST) # any diff --git a/integration_tests/callback_03.py b/integration_tests/callback_03.py new file mode 100644 index 0000000000..0f1f62e722 --- /dev/null +++ b/integration_tests/callback_03.py @@ -0,0 +1,13 @@ +from lpython import i32, Callable + +def foo(x : i32) -> None: + print(x) + assert x == 3 + +def bar(func : Callable[[i32], None], arg : i32) -> i32: + func(arg) + +def main0(): + bar(foo, 3) + +main0()