-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Feature request: provide more information when an @required parameter is null #36524
Comments
Wouldn't you use the second field in : assert(bar != null, 'Required parameter bar must not be null') |
Something to consider if we introduce an actual keyword to replace |
Cf. dart-lang/language#156 (comment), such a keyword could very well be introduced, and it would be implied (maybe without the keyword, maybe the keyword would be mandatory) that a named parameter with a non-null type and no default is required. It wouldn't make sense to require a named parameter with a default value to be passed, so it should most likely be an error to have that. I think there wouldn't be an obvious justification for the converse rule: A named parameter whose type is nullable could be required and it could be optional, with and without a default value, all combinations will work and might make sense in the given application context (so we might as well allow developers to make the choice using an explicit With that, this could be considered as yet another voice in favor of an explicit |
@matanlurey you're right, we could generate a reasonable message (even a link to the API doc) by hand. There are loads of these, so it would be nice if it the reasonable message was generated by default. |
The issue here is @HansMuller: On a related note, I think your own team requested a lint to enforce adding messages? |
@matanlurey: yes we did request such a lint. Once that's landed we'll be asking for a lint that checks if the messages are actually helpful :-). |
It's common for @required named parameters to be non-null.
Currently, upon "hot restart", this idiomatic Flutter class fails with:
It would be somewhat more informative if it failed with a message like:
For Flutter classes it might also be helpful if a link to the API doc for the required parameter was provided.
This issue was originally reported here: flutter/flutter#29046 (comment)
The text was updated successfully, but these errors were encountered: