Skip to content

lpython can't handle calback returning None / void #2206

Closed
@emoise-gsi

Description

@emoise-gsi

This is related to #2169.
lpython version v.0.18.4

Consider the following code, callback_bug.py:

from lpython import ccallback, i32, Callable

def foo(x : i32) -> None:
    print(x)

def bar(func : Callable[[i32], None], arg : i32) -> i32:
    func(arg)

@ccallback
def entry_point() -> None:
    bar(foo, 3)

Compiling with lpython:
$ lpython callback_bug.py --show-c
semantic error: Only Name, Subscript, and Call supported for now in annotation of annotated assignment.
--> func_ptr/func_ptr_bug.py:6:1 - 7:13
|
6 | def bar(func : Callable[[i32], None], arg : i32) -> i32:
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...
...
|
7 | func(arg)
| ...^^^^^^^^^^^^^

The problem seems to be with the None return value of the callback. If we replace it with i32 it compiles just fine:

from lpython import ccallback, i32, Callable

def foo(x : i32) -> i32:
    print(x)
    return x

def bar(func : Callable[[i32], i32], arg : i32) -> i32:
    return func(arg)

@ccallback
def entry_point() -> None:
    bar(foo, 3)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions