-
Notifications
You must be signed in to change notification settings - Fork 171
Support struct initialization with named arguments #1813
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Beautiful, thank you!
fixes #1800.