lpython
lpython copied to clipboard
Bug: Catch errors with arrangement of positional & keyword arguments in function definition and call
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.