← 输入框|github.com|刷新
Skip to content

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

Closed

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)

Activity

  1. certik commented on Jul 24, 2023

    @certik
    Contributor

    Great catch, thank you!

  2. added
    bug
    on Jul 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions