Skip to content

Default initialize function argument, closes #1090 #1092

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

Merged
merged 2 commits into from
Jun 16, 2024

Conversation

sookach
Copy link
Contributor

@sookach sookach commented May 31, 2024

@hsutter @bluetarpmedia
This patches #1090 by allowing defaulting of arguments in a function call by use of '()' (akin to '{}' in C++).

@sookach sookach force-pushed the pr/default_arg branch 2 times, most recently from 70670c3 to c181fb1 Compare May 31, 2024 03:45
@sookach sookach changed the title [to_cpp1] Default initialize function argument Default initialize function argument May 31, 2024
@MaxSagebaum
Copy link
Contributor

Looks good, a regression test would be nice.

@sookach
Copy link
Contributor Author

sookach commented May 31, 2024

Looks good, a regression test would be nice.

Yeah, it passed on my fork
https://github.com/sookach/cppfront/tree/pr/default_arg

but it looks like the tests don't run on their own in this repo?

@gregmarr
Copy link
Contributor

but it looks like the tests don't run on their own in this repo?

https://docs.github.com/en/actions/managing-workflow-runs/approving-workflow-runs-from-public-forks

By default, all first-time contributors require approval to run workflows.

@MaxSagebaum
Copy link
Contributor

Looks good, a regression test would be nice.

Yeah, it passed on my fork
https://github.com/sookach/cppfront/tree/pr/default_arg

but it looks like the tests don't run on their own in this repo?

Ah, what I meant, is that it would be nice if you add a regression test for the new feature. Sorry for the misunderstanding.

@sookach
Copy link
Contributor Author

sookach commented Jun 1, 2024

Cool, added a regression test. Let me know what you think.

Copy link
Contributor

@MaxSagebaum MaxSagebaum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for adding the test. It looks good to me. I just have a minor comment.

source/parse.h Outdated
Comment on lines 5906 to 5909
is_inside_call_expr = true;

term.expr_list = expression_list(term.op, lexeme::RightParen);

is_inside_call_expr = false;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought, that it might be better to add is_inside_call_expr as an argument. But I think from the geeneral design it is not possible. So the state modification is ok. In order to make the more prominent, I would changed it to:

Suggested change
is_inside_call_expr = true;
term.expr_list = expression_list(term.op, lexeme::RightParen);
is_inside_call_expr = false;
is_inside_call_expr = true; // Flag this expression list parse.
term.expr_list = expression_list(term.op, lexeme::RightParen);
is_inside_call_expr = false;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. Done.

Copy link
Owner

@hsutter hsutter Jun 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, it's either use out-of-band state, or wire a parameter through the call chain. Sometimes I do the former, sometimes the latter, depending on the situation.

@hsutter hsutter changed the title Default initialize function argument Default initialize function argument, closes #1090 Jun 16, 2024
@hsutter
Copy link
Owner

hsutter commented Jun 16, 2024

Thanks!

@hsutter hsutter merged commit 94bea67 into hsutter:main Jun 16, 2024
18 of 25 checks passed
JohelEGP added a commit to JohelEGP/cppfront that referenced this pull request Oct 4, 2024
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

Successfully merging this pull request may close these issues.

4 participants