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

Purpose of required before named non-nullable arguments #2989

Closed
MohammedAsaadAsaad opened this issue Apr 10, 2023 · 2 comments
Closed

Purpose of required before named non-nullable arguments #2989

MohammedAsaadAsaad opened this issue Apr 10, 2023 · 2 comments
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists

Comments

@MohammedAsaadAsaad
Copy link

I'm wondering what is the purpose of 'required' key word used with named non-nullable arguments?!
After null-safety, do really we need to put 'required' before the non-nullable named argument?
Implicitly, the compiler consider it as required and forces the developer to use it, so. why we need to write it?
Thanks.

@MohammedAsaadAsaad MohammedAsaadAsaad added the feature Proposed language feature that solves one or more problems label Apr 10, 2023
@mateusfccp
Copy link
Contributor

Duplicate: #1502, #878.

@lrhn
Copy link
Member

lrhn commented Apr 10, 2023

Yep, as discussed before, the required is still required in function types, because it's possible to have an optional non-nullable parameter with a default value, and function types don't include the default value.
In actual functions, it's technically only needed if you have a nullable required parameter, because the presence of a default value would mean optional, and its absence would then imply required for non-nullable types.

But for consistency and simplicity, required is required on every required named parameter, everywhere.

@lrhn lrhn closed this as completed Apr 10, 2023
@lrhn lrhn added the state-duplicate This issue or pull request already exists label Apr 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Proposed language feature that solves one or more problems state-duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

3 participants