-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Migrate null assert main to null safety #84060
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
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie on the #hackers channel in Chat. If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
| void methodThatAcceptsNonNull(int? x) { | ||
| print(x! + 2); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the added ? and ! here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are trying to pass null here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@goderbauer we need to pass null here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. Isn't the point of the function that the method only accepts non-null values? In other words, just removing the comment // @dart = 2.12 should be enough after reverting these changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @shihaohong
here we need to pass null value. So how should I deal with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Abhishek01039 can you explain why we need to pass a null value here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Piinks we need to assert here but I think we can remove this file dev/integration_tests/web/lib/null_assert_main.dart
Piinks
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you check the analyzer here? It looks like it is unhappy.
|
Yes because we are trying to pass a null value to a non-nullable variable. |
|
@jonahwilliams it looks like you added these files as part of #61114. This PR is part of an effort to finish migrating everything to null safety. However, it would appear that these files only make sense to test with null safety turned off. Should we just leave them untouched because we still need them, or can we remove them now that everything is being moved to null safety? |
|
Only a very small % of the Dart/Flutter ecosystem is migrated to null safety, so we still need to test this until a hypothetical Dart 3.0 / Removal of null unsafe code |
Ok, sounds good. @Abhishek01039 thanks so much for helping with this, but it looks like we should just leave these files as is. I will go ahead and close this out. |

part of #84014