-
Notifications
You must be signed in to change notification settings - Fork 205
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
Rethink required
to be optional for non-nullable named parameters without default values
#3206
Comments
If the request is to be able to omit For all other methods and constructors, the arguments from the existing issues still apply. Omitting a That would be a named parameter with no default value that:
The problem with being implicit is that it allows errors to propagate. If you intended a parameter to be required, but its type ended up being nullable, the parameter is now optional. Or you intend a parameter to be optional, but accidentally erased its default value, and it's now required. void testFoo(String name, Foo expectedResult, int arg1, {String arg2 = theDefaultValue}) {
test(name, () {
expect(Foo(arge, arg2: arg2), equals(expectedResult)); // arg2 always passed!
}
} so you never actually test that the default value is there. Safety sometimes require redundancy. Allowing you to omit I'm not sold. (I'd much rather just make every parameter required if it has no default value. Then you must add |
I knew default values are not parts of function signatures. |
There already have been several discussions such as #156, #878, #2050, and so on.
But, I think it is good time to rethink
required
to be optional.Supporse,
final
can be inferred by the compiler, because otherwise it is an error.On the other hand,
required
is required!I feel it weird.
Especially in context of primary constructors, terse syntax is justice.
Specify primary constructors by eernstg · Pull Request #3023 · dart-lang/language
In addition, under migration to null-safe code,
{int i}
had to be decided/ marked whether nullable{int? i}
or required{required int i}
by users.Now, Dart 3 is fully null-safe and the migration tool has gone.
The text was updated successfully, but these errors were encountered: