Skip to content

Commit 3fcf814

Browse files
authored
Merge pull request #2207 from Shaikh-Ubaid/support_func_with_no_ret_as_callback
Support function with no return type as callback
2 parents a394303 + b7f9127 commit 3fcf814

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

integration_tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ RUN(NAME global_syms_06 LABELS cpython llvm c)
722722

723723
RUN(NAME callback_01 LABELS cpython llvm c)
724724
RUN(NAME callback_02 LABELS cpython llvm c)
725+
RUN(NAME callback_03 LABELS cpython llvm c)
725726

726727
# Intrinsic Functions
727728
RUN(NAME intrinsics_01 LABELS cpython llvm NOFAST) # any

integration_tests/callback_03.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from lpython import i32, Callable
2+
3+
def foo(x : i32) -> None:
4+
print(x)
5+
assert x == 3
6+
7+
def bar(func : Callable[[i32], None], arg : i32) -> i32:
8+
func(arg)
9+
10+
def main0():
11+
bar(foo, 3)
12+
13+
main0()

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1703,6 +1703,10 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
17031703
abi, is_argument);
17041704
}
17051705

1706+
if (AST::is_a<AST::ConstantNone_t>(annotation)) {
1707+
return nullptr;
1708+
}
1709+
17061710
if (AST::is_a<AST::Subscript_t>(annotation)) {
17071711
AST::Subscript_t *s = AST::down_cast<AST::Subscript_t>(&annotation);
17081712
if (AST::is_a<AST::Name_t>(*s->m_value)) {

0 commit comments

Comments
 (0)