Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Catch errors with arrangement of positional & keyword arguments in function definition and call #2679

Open
kmr-srbh opened this issue May 3, 2024 · 0 comments

Comments

@kmr-srbh
Copy link
Contributor

kmr-srbh commented May 3, 2024

Currently LPython fails in detecting the correct arrangement of arguments in a function's definition. The bug is chiefly that the compiler allows keyword arguments before positional ones, both when defining the function and calling it.

from lpython import i32

def fn(arg1: i32=1, arg2: i32, arg3: i32) -> i32:
    return arg1 + arg2 + arg3

print(fn(2, 1, 3))
(lp) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
6

Note that arg1: i32=1, which is a default argument, is followed by 2 other non-default arguments. LPython should catch the incorrect function definition and throw the required SyntaxError as CPython does.

from lpython import i32

def fn(arg1: i32, arg2: i32, arg3: i32=1) -> i32:
    return arg1 + arg2 + arg3

print(fn(arg3=2, 1, 3))
(lp) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
6

In the above example, a keyword argument is followed by non-keyword arguments. LPython should catch invalid function calls and throw the required SyntaxError.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant