Support struct initialization with named arguments#1813
Support struct initialization with named arguments#1813certik merged 4 commits intolcompilers:mainfrom
Conversation
| // Keyword arguments handled in make_call_helper | ||
| #define parse_args() if( x.n_keywords == 0 ) { \ | ||
| args.reserve(al, x.n_args); \ | ||
| visit_expr_list(x.m_args, x.n_args, args); \ | ||
| } \ |
There was a problem hiding this comment.
Here, I was overlooking the first line if( x.n_keywords == 0 ) { \. Hence, I refactored this into a function, which I am hoping is more readable.
|
I added some general error situations in The working of named arguments is not yet perfect or exactly similar to For example: s = S(1, c=2, 3)For the above, the ast contains $ cat examples/expr2.py
from lpython import i32, dataclass
@dataclass
class S:
a: i32
b: i32
c: i32
def main0():
s:S = S(1,c=2,3)
print(s.a)
print(s.b)
print(s.c)
main0()
$ python examples/expr2.py
File "/Users/ubaid/Desktop/OpenSource/lpython/examples/expr2.py", line 10
s:S = S(1,c=2,3)
^
SyntaxError: positional argument follows keyword argument
$ lpython examples/expr2.py
1
3
2 |
|
Ready. |
fixes #1800.