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

Default parameters in constructors #1840

Merged
merged 2 commits into from
Mar 7, 2024

Conversation

badboy
Copy link
Member

@badboy badboy commented Nov 10, 2023

This PR is a two-parter:

The first 2 commits essentially implement what we discussed in #1658:
Struct constructors use named parameters in the foreign language.
This is enforced for Ruby and Python. Swift enforces it by default anyway, in Kotlin it's optional but usable (I don't think one can enforce the names)
That means default values at any position just work.
Note: default values for constructors aren't implemented for Ruby in main right now at all.

The last commit looks at default values in functions:
Right now we happily accept default values for any of the arguments, which will break for Python and Ruby if any defaulted args come before non-defaulted ones.


I put this up as one PR for now, but that doesn't mean it's final.
I'd be happy to split it up later.
Personally I think for constructors it's not so controversial anymore (but awaiting final decision in #1658).
For functions it's unclear right now.

@badboy
Copy link
Member Author

badboy commented Dec 13, 2023

In order to get something landed and to reduce the scope I'm splitting this in two: the record constructor and the normal function and its argument's order.

This PR is now purely for the constructor as that seems uncontroversial.

@badboy badboy changed the title Default parameters in constructors and functions Default parameters in constructors Dec 13, 2023
@badboy badboy force-pushed the 1658/record-default-values-in-any-order branch from 830570b to 8d40d92 Compare December 13, 2023 13:07
@badboy badboy marked this pull request as ready for review December 13, 2023 13:07
@badboy badboy requested a review from a team as a code owner December 13, 2023 13:07
@badboy badboy requested review from skhamis and removed request for a team December 13, 2023 13:07
@badboy
Copy link
Member Author

badboy commented Dec 13, 2023

There's a bunch of tests that are affected by this change. So I'll wait for feedback if we go with this before spending the time on fixing them.

Copy link
Member

@mhammond mhammond left a comment

Choose a reason for hiding this comment

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

This looks great to me - I'll also flag @jeddai as the reviewer

fixtures/struct-default-values/README.md Show resolved Hide resolved
@mhammond mhammond requested review from jeddai and removed request for skhamis December 13, 2023 14:52
Copy link
Member

@jeddai jeddai left a comment

Choose a reason for hiding this comment

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

This looks good to me, I'm excited to have this in!

@bendk bendk mentioned this pull request Dec 21, 2023
2 tasks
@mhammond mhammond added the v0.26 label Dec 21, 2023
@mhammond mhammond removed the v0.26 label Jan 18, 2024
@badboy badboy force-pushed the 1658/record-default-values-in-any-order branch 2 times, most recently from 1d2e20a to b9f16a3 Compare February 26, 2024 16:38
badboy added 2 commits March 7, 2024 12:38
BREAKING CHANGE:
Named arguments to struct constructors are now required.
Note that this now allows default values before non-default ones, which
previously lead to a syntax error in generated Python.
…t values in struct constructors

BREAKING CHANGE: Named arguments are now required.
@badboy badboy force-pushed the 1658/record-default-values-in-any-order branch from b9f16a3 to 2e5bc9f Compare March 7, 2024 11:39
@badboy badboy merged commit 0bb6eae into main Mar 7, 2024
5 checks passed
@badboy badboy deleted the 1658/record-default-values-in-any-order branch March 7, 2024 15:23
mgeisler added a commit to mgeisler/mls-rs that referenced this pull request Mar 22, 2024
UniFFI added support for async traits in mozilla/uniffi-rs#1981, but
this is not yet released. This commit temporarily introduces a Git
dependency on UniFFI to let us test the async functionality which was
removed in awslabs#86.

An unrelated UniFFI change (mozilla/uniffi-rs#1840) made our existing
test fail.
mgeisler added a commit to mgeisler/mls-rs that referenced this pull request Mar 22, 2024
UniFFI added support for async traits in mozilla/uniffi-rs#1981, but
this is not yet released. This commit temporarily introduces a Git
dependency on UniFFI to let us test the async functionality which was
removed in awslabs#86.

An unrelated UniFFI change (mozilla/uniffi-rs#1840) made our existing
test fail.
mgeisler added a commit to mgeisler/mls-rs that referenced this pull request Mar 23, 2024
UniFFI added support for async traits in mozilla/uniffi-rs#1981, but
this is not yet released. This commit temporarily introduces a Git
dependency on UniFFI to let us test the async functionality which was
removed in awslabs#86.

An unrelated UniFFI change (mozilla/uniffi-rs#1840) made our existing
test fail.
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.

3 participants